@actualwave/promised-timeout 中文文档教程
@actualwave/promised-timeout
返回承诺的函数集,将在特定超时后解决。 它最适合与异步/等待一起使用。
import timeout from '@actualwave/promised-timeout';
async function test() {
console.log('Before');
await timeout(1000);
console.log('After a second');
}
Installation
通过 NPM
npm install @actualwave/promised-timeout --save
或 yarn
yarn add @actualwave/promised-timeout
API
可用
- timeout() -- Present as default or named export, resolves after specified number of milliseconds
- aTick -- Returns a promise which resolves on next tick
- aQuarterSecond -- Returns a promise which resolves after a quarter of second
- aHalfSecond -- Returns a promise which resolves after a half of second
- aSecond -- Returns a promise which resolves after a second
- aQuarterMinute -- Returns a promise which resolves after a quarter of minute
- aHalfMinute -- Returns a promise which resolves after a half of minute
- aMinute -- Returns a promise which resolves after a minute
- aQuarterHour -- Returns a promise which resolves aftera quarter of hour
- aHalfHour -- Returns a promise which resolves after a half of hour
- anHour -- Returns a promise which resolves after an hour
的函数 这些具有预定义超时的函数应该涵盖大多数 timeout()
用法:
import { aSecond, aTick } from '@actualwave/promised-timeout';
async function test() {
console.log('Before');
await aSecond();
console.log('After a second');
await aTick();
console.log('Next tick');
}
常量可用
- QUARTER_SECOND -- 250, quarter of second in milliseconds
- HALF_SECOND -- 500, half of second in milliseconds
- SECOND -- 1000, second in milliseconds
- QUARTER_MINUTE -- 15000, quarter of minute in milliseconds
- HALF_MINUTE -- 30000, half of minute in milliseconds
- MINUTE -- 60000, minute in milliseconds
- QUARTER_HOUR -- 900000, quarter of hour in milliseconds
- HALF_HOUR -- 1800000, half of hour in milliseconds
- HOUR -- 3600000, an hour in milliseconds
常量可以与 timeout()
函数一起使用。
import timeout, { SECOND } from '@actualwave/promised-timeout';
async function test() {
console.log('Before');
await timeout(SECOND);
console.log('After a second');
}
@actualwave/promised-timeout
Set of functions that return promise which will be resolved after a specific timeout. It best suited to use with async/await.
import timeout from '@actualwave/promised-timeout';
async function test() {
console.log('Before');
await timeout(1000);
console.log('After a second');
}
Installation
Via NPM
npm install @actualwave/promised-timeout --save
Or yarn
yarn add @actualwave/promised-timeout
API
Functions available
- timeout() -- Present as default or named export, resolves after specified number of milliseconds
- aTick -- Returns a promise which resolves on next tick
- aQuarterSecond -- Returns a promise which resolves after a quarter of second
- aHalfSecond -- Returns a promise which resolves after a half of second
- aSecond -- Returns a promise which resolves after a second
- aQuarterMinute -- Returns a promise which resolves after a quarter of minute
- aHalfMinute -- Returns a promise which resolves after a half of minute
- aMinute -- Returns a promise which resolves after a minute
- aQuarterHour -- Returns a promise which resolves aftera quarter of hour
- aHalfHour -- Returns a promise which resolves after a half of hour
- anHour -- Returns a promise which resolves after an hour
These functions with predefined timeouts should cover majority of timeout()
usages:
import { aSecond, aTick } from '@actualwave/promised-timeout';
async function test() {
console.log('Before');
await aSecond();
console.log('After a second');
await aTick();
console.log('Next tick');
}
Constants available
- QUARTER_SECOND -- 250, quarter of second in milliseconds
- HALF_SECOND -- 500, half of second in milliseconds
- SECOND -- 1000, second in milliseconds
- QUARTER_MINUTE -- 15000, quarter of minute in milliseconds
- HALF_MINUTE -- 30000, half of minute in milliseconds
- MINUTE -- 60000, minute in milliseconds
- QUARTER_HOUR -- 900000, quarter of hour in milliseconds
- HALF_HOUR -- 1800000, half of hour in milliseconds
- HOUR -- 3600000, an hour in milliseconds
Constants can be used with timeout()
function.
import timeout, { SECOND } from '@actualwave/promised-timeout';
async function test() {
console.log('Before');
await timeout(SECOND);
console.log('After a second');
}