1.0.4 • Published 2 years ago

waitit v1.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Wait it for JavaScript

Wait until a condition matched.

Usage

It shows you how to install the package, and how to use it from your projects.

Installation

npm install waitit

Samples

Wait for completion, e.g. 5 ticks

let condition = false;
setTimeout(() => {
  condition = true;
}, 1);

try {
  const wait = await waitit.start({
    check: () => {
      return condition;
    },
    maxTicks: 5
  });
  console.log(wait); // { code: 'COMPLETED' }
}
catch(error) {
  console.log(error);
}

Timeout example

let condition = false;
setTimeout(() => {
  condition = true;
}, 10000);
try {
  const wait = await waitit.start({
    check: () => {
      return condition;
    },
    maxTicks: 3
  });
  console.log(wait);
}
catch(error) {
  console.log(error);  // { code: 'TIMEOUT' }
}

Cancellation

let condition = false;

waitit.start({
  check: () => {
    return condition;
  }
}).then((wait) => {
  console.log(wait);
}).catch(error => {
  console.log(error); // { code: 'CANCELLED' }
});
// Force it to stop
setTimeout(() => {
  waitit.stop();
}, 1000);
1.0.4

2 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago