a-mimir
v1.0.1
Published
async and sync sleep functions
Downloads
6
Maintainers
Readme
a-mimir
Barebones sleep functions. As simple and boring as it gets
Usage
import { sleep } from "a-mimir";
// block the current thread (doesn't work in the browser main thread, but works in node and web workers)
sleep.sync(500); // block for 500ms
// schedule an action to run later, without blocking the main thread. works everywhere
const promise = sleep.async(500); // promise which resolves in 500ms
promise.then(() => {
console.log("is printed second");
});
console.log("is printed first");
Notes
sleep.sync
relies on the globalsSharedArrayBuffer
,Int32Array
, andAtomics.wait
.sleep.async
relies on the globalsPromise
andsetTimeout
.
License
MIT