2.2.0 • Published 2 years ago

@honeo/sleep v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

sleep

なにこれ

よくあるPromiseなsleep関数。

使い方

$ npm i @honeo/sleep
// ESM
import sleep from '@honeo/sleep';

// Dynamic import & CDN
const {default: sleep} = await import('https://raw.githack.com/honeo/sleep/master/index.mjs');


await sleep(1000, 'foobar').then( (arg)=>{
	console.log(arg); // after 1sec "foobar"
});

API

sleep([ms|date [, arg , options]])

// 1sec
await sleep(1000);

// promise<"foo">
await sleep(1000, 'foo');

// AbortController
await sleep(1000, 'bar', {
	signal: new AbortController().signal
}).catch( (err)=>{
	console.log(err.message); // "sleep: aborted"
});

// date
const date_after1s = new Date(Date.now()+1000);
await sleep(date_after1s);

// very fucking bad
sleep(1000, null, {
	sync: true
});


// default
sleep(1, undefined, {
	sync: false
});

Breaking Changes

v2

CommonJS

廃止。

sleep()

引数1にdefault値を設定。

register (Promise.prototype.sleep)

廃止。

2.2.0

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago