npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

isomorphic-timers-promises

v1.0.1

Published

`timers/promises` for client and server.

Downloads

1,818,196

Readme

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

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

Usage with Rollup

// 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

| Property | Type | Default | Description | | ---------------- | ------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | delay | number | 1 | The number of milliseconds to wait before fulfilling the promise. | | value | * | | A value with which the promise is fulfilled. | | options.ref | boolean | true | Set to false to indicate that the scheduled timeout should not require the event loop to remain active. Valid only for server environment. | | options.signal | AbortSignal | | An optional AbortSignal that can be used to cancel the scheduled timeout. |

setImmediate([value[, options]])

Returns: Promise

| Property | Type | Default | Description | | ---------------- | ------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | | value | * | | A value with which the promise is fulfilled. | | options.ref | boolean | true | Set to false to indicate that the scheduled immediate should not require the event loop to remain active. Valid only for server environment. | | options.signal | AbortSignal | | An 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.

| Property | Type | Default | Description | | ---------------- | ------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | | delay | number | 1 | The number of milliseconds to wait between iterations. | | value | * | | A value with which the iterator returns. | | options.ref | boolean | true | Set 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.signal | AbortSignal | | An 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ć