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

@sha1n/about-time

v0.1.0

Published

A set of essential time related utilities

Downloads

48

Readme

CI Coverage GitHub npm type definitions npm

About-Time

A collection of essential time related utilities.

Install

npm i @sha1n/about-time

Utilities & Features

delay

// Executes a function with delay and returns it's value
await delay(action, { time: 10 });
await delay(action, { time: 10, units: TimeUnit.Milliseconds });
await delay(action, { time: 10, units: TimeUnit.Milliseconds, unref: true });

delayed

// Returns a new function that executes the specified action with delay and returns it's value
const delayedAction = delayed(action, { time: 10, units: TimeUnit.Milliseconds, unref: true });
const result = await delayedAction();

timeoutAround

// Executes a function and guards it with a specified timeout
await timeoutAround(action, { time: 10 });
await timeoutAround(action, { time: 10, units: TimeUnit.Milliseconds });
await timeoutAround(action, { time: 10, units: TimeUnit.Milliseconds, unref: true });

timeBounded

Wraps a given function with timeoutAround with the specified arguments.

const timeBoundAction = timeBounded(action, options);
const result = await timeBoundAction();

sleep

// Pauses execution for a specified amount of time
await sleep(10);
await sleep(10, { units: TimeUnit.Seconds });
await sleep(10, { units: TimeUnit.Seconds, unref: true });

stopwatch

// Measure time between actions
const elapsed = stopwatch();
    
// do stuff here...

const elapsed1 = elapsed(TimeUnit.Milliseconds);

// do more stuff here...

const elapsed2 = elapsed(TimeUnit.Seconds);

until / eventually

// Waits for a condition to become true
await until(condition, { deadline: 10000 });
await until(condition, { deadline: 10000, interval: 100 });
await until(condition, { deadline: 10000, interval: 100, units: TimeUnit.Milliseconds });
await until(condition, { deadline: 10000, interval: 100, units: TimeUnit.Milliseconds, unref: true });

Retry

RetryPolicy

Simple retry policy

// 3 retries with 10 seconds wait between each
const retryPolicy = simpleRetryPolicy(3, 10, TimeUnit.Seconds);

Fixed retry policy

// 4 retries after 3, then after 10, 50 and 100 milliseconds
const retryPolicy = fixedRetryPolicy([3, 10, 50, 100], TimeUnit.Milliseconds);

Exponential backoff retry policy

Exponential backoff formula based retry policy with optional custom exponent base and a limit. The optional limit provides control over maximum pause intervals, so they don't soar beyond reasonable values.

The formula used by this implementation is the following:

intervali = min(limit, (exponentiali - 1) / 2)

const retryPolicy = exponentialBackoffRetryPolicy(/* count = */10, /* opts?: { exponential?: number, limit?: number, units?: TimeUnit }*/);

retryAround

Executes the given function with retries based on the specified policy and optional predicate. The predicate provides control over which errors we want to retry on.

const result = await retryAround(action, retryPolicy, predicate);

retriable

Wraps a given function with retryAround with the specified arguments.

const retriableAction = retriable(action, retryPolicy, predicate);
const result = await retriableAction();