@actualwave/promised-timeout
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

@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');
}

Package Sidebar

Install

npm i @actualwave/promised-timeout

Weekly Downloads

1

Version

0.0.7

License

MIT

Unpacked Size

5.22 kB

Total Files

4

Last publish

Collaborators

  • actualwave