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

@iqrok/intime

v0.1.1

Published

Interval and Timeout in microseconds

Downloads

5

Readme

InTime

SetTimeout & SetInterval in microseconds.

This package is using Node-API and the implentation is done in C++, so it only works in Node.js.

The timing is implemented by using sleep. In Linux, clock_nanosleep is used to invoke sleep. In Windows, SetWaitableTimer is used instead. If more accurate timing is needed, then busy wait can be used by setting busy wait period. If busy wait period is longer than sleep period, then busy wait will be disabled.

Installation

npm i @iqrok/intime

Usage

const intime = require('@iqrok/intime');
const { SetInterval, SetTimeout, ClearInterval, CancelTimeout } = intime;

// SetInterval 25,000 us
const interval1 = SetInterval(elapsed_us => console.log(elapsed_us), 25_000);

// SetInterval 30,000 us with 200 us busy wait
const interval2 = SetInterval(elapsed_us => console.log(elapsed_us), 30_000, 200);

// clear interval1 after 1 second
SetTimeout(elapsed_us => {
	ClearInterval(interval1);
	console.log('Done in', elapsed_us / 1e6, 's');
}, 1000_000);

// clear interval2 after 2 seconds
SetTimeout(elapsed_us => {
	ClearInterval(interval2);
	console.log('Done in', elapsed_us / 1e6, 's');
}, 2000_000);

const canceled = SetTimeout(elapsed_us => {
	console.log('this callback won\'t be called');
}, 1500_000);

CancelTimeout(canceled);

Methods

  • SetInterval(callback, us[, busy]) | params | Type | | Description | |------------|------------|--------|----------------------------------| |callback |Function| |Callback function to be executed | |us |Number | |delay in microseconds | |busy |Number |optional|busy wait duration in microseconds| | | |Returns |Number | |SetInterval id |

  • ClearInterval(id) | params | Type | | Description | |------------|------------|--------|----------------------------------| |id |Number | |SetInterval id to be cleared | | | |Returns |Promise | |Rejects if id is not found |

  • SetTimeout(callback, us[, busy]) | params | Type | | Description | |------------|------------|--------|----------------------------------| |callback |Function| |Callback function to be executed | |us |Number | |delay in microseconds | |busy |Number |optional|busy wait duration in microseconds| | | |Returns |Number | |SetTimeout id |

  • CancelTimeout(id) | params | Type | | Description | |------------|------------|--------|----------------------------------| |id |Number | |SetTimeout id to be canceled | | | |Returns |Promise | |Rejects if id is not found |

    Note: Canceling timeout won't clear the timeout itself, it only makes the callback not to be executed once the timeout is done.

  • DelayMs(ms[, busy_ms]) | params | Type | | Description | |------------|------------|--------|----------------------------------| |ms |Number | |Delay in milliseconds | |busy_ms |Number |optional|Busy Wait duration in milliseconds|

  • DelayUs(us[, busy_us]) | params | Type | | Description | |------------|------------|--------|----------------------------------| |us |Number | |Delay in microseconds | |busy_us |Number |optional|Busy Wait duration in microseconds|

Callback

| params | Type | | Description | |------------|------------|--------|-----------------------------------------------------| |elapsed_us|Number | |Duration of SetInterval or SetTimeout in microseconds| Note: Currently, the callback can't accept additional parameters.