npm.io
0.1.0 • Published 3 years ago

@steeringwaves/sleep

Licence
ISC
Version
0.1.0
Deps
1
Size
126 kB
Vulns
0
Weekly
0

@steeringwaves/sleep

workflow

A typescript async sleep utility.

Example

Promises

const Sleep = require("@steeringwaves/sleep").default;

Sleep(500).then(() => console.log("500ms sleep finished")); // sleep 500ms
await Sleep(1000); // sleep 1s
console.log("1s sleep finished");
Using contexts
const Context = require("@steeringwaves/context").default;
const Sleep = require("@steeringwaves/sleep").default;

const ctx = new Context();

Sleep(2000)
	.setContext(ctx)
	.onCancel(() => {
		console.log("sleep canceled");
	})
	.then(() => console.log("sleep completed"))
	.catch((e) => console.log(e));

ctx.Done();