Socket
Socket
Sign inDemoInstall

isomorphic-timers-promises

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    isomorphic-timers-promises

`timers/promises` for client and server.


Version published
Weekly downloads
244K
increased by0.64%
Maintainers
1
Install size
61.8 kB
Created
Weekly downloads
 

Changelog

Source

[1.0.1][] - 2021-06-30

Added

  • Configuration for Node support

Readme

Source

isomorphic-timers-promises

Build Status BrowserStack Status

timers/promises for client and server.

The timers/promises API provides an alternative set of timer functions that return Promise objects.

Install

npm install isomorphic-timers-promises --save

Usage

import {
	setTimeout,
	setImmediate,
	setInterval
} from 'isomorphic-timers-promises';

(async () => {
	const result = await setTimeout(100, 'becky');
	console.log(result); // 'becky'
})();

(async () => {
	const result = await setImmediate('maya');
	console.log(result); // 'maya'
})();

(async () => {
	let result = 0;
	for await (const startTime of setInterval(100, Date.now())) {
		const now = Date.now();
		result = result + 1;
		if (now - startTime >= 1000) {
			break;
		}
	}
	console.log(result); // 10
})();

Usage with Webpack

Show me
// webpack.config.js
module.exports = {
	// ...
	resolve: {
		alias: {
			'timers/promises': 'isomorphic-timers-promises'
		}
	}
};

Usage with Rollup

Show me
// rollup.config.js
const { default: resolve } = require('@rollup/plugin-node-resolve');
const alias = require('@rollup/plugin-alias');

module.exports = {
	// ...
	plugins: [
		resolve(),
		alias({
			entries: {
				'timers/promises': 'isomorphic-timers-promises'
			}
		})
	]
};

API

setTimeout([delay[, value[, options]]])

Returns: Promise

PropertyTypeDefaultDescription
delaynumber1The number of milliseconds to wait before fulfilling the promise.
value*A value with which the promise is fulfilled.
options.refbooleantrueSet to false to indicate that the scheduled timeout should not require the event loop to remain active. Valid only for server environment.
options.signalAbortSignalAn optional AbortSignal that can be used to cancel the scheduled timeout.

setImmediate([value[, options]])

Returns: Promise

PropertyTypeDefaultDescription
value*A value with which the promise is fulfilled.
options.refbooleantrueSet to false to indicate that the scheduled immediate should not require the event loop to remain active. Valid only for server environment.
options.signalAbortSignalAn optional AbortSignal that can be used to cancel the scheduled immediate.

setInterval([delay[, value[, options]]])

Returns: async iterator that generates values in an interval of delay.

PropertyTypeDefaultDescription
delaynumber1The number of milliseconds to wait between iterations.
value*A value with which the iterator returns.
options.refbooleantrueSet to false to indicate that the scheduled timeout between iterations should not require the event loop to remain active. Valid only for server environment.
options.signalAbortSignalAn optional AbortSignal that can be used to cancel the scheduled timeout between operations.

Node and browser support

Supports Node 10+.

Tested in Chrome 72, Firefox 65, Internet Explorer 11 and should work in all modern browsers.

Check support based on Browserslist configuration).

Assumes Promise, AbortController and setImmediate are polyfilled or available in global context.

Test

For automated tests, run npm run test:automated (append :watch for watcher support).

Test suite is taken and modified from official Node.js repository (setTimeout, setImmediate, setInterval).

License

MIT © Ivan Nikolić

Keywords

FAQs

Last updated on 30 Jun 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc