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 🙏

© 2026 – Pkg Stats / Ryan Hefner

tasklike-promise-library

v0.0.13

Published

A .NET-Task-like Promise extension library for JavaScript.

Readme

npm Github issues Github

tasklike-promise-library

A .NET-Task-like Promise extension library for JavaScript. It relieves some of the pain caused by the feature gap of current Promise infrastructure in a .NET Task Parallel Library fashion, such as

  • Promise cooperative cancellation with ICancellationToken.
  • Promise that resolves after certain period of time (delay).
  • Promise that can be resolved/rejected/cancelled from outside, somewhat like Deferred or $.Deferred (PromiseResolutionSource).
  • Some cancellable & awaitable wrappers for asynchronous callbacks, such as asynchronous XHR (sendRequest), RAF(requestAnimationFrameAsync), idle callback(requestIdleCallbackAsync).

Please note that this library depends on ES6 Promise (e.g. constructor, Promise.resolve, Promise.reject) to work, and we does not provide Promise polyfill here. If you need such thing, please get yourself a polyfill first. (core-js is a nice one.)

Installation

This package contains TS definitions itself, so using one of the the following lines is enough

npm install --save tasklike-promise-library
# or
yarn add tasklike-promise-library

Documentation

Full API documentation is here.

Example

The following is a quick demonstration of use cases. For a full typescript example, see the example folder. Live example is here.

delay

See common module.

import { delay, ICancellationToken } from "tasklike-promise-library";

async function doSomeWork(ct?: ICancellationToken) {
    ct.throwIfCancellationRequested();
    // do something
    await delay(1000, ct);
    // do something else
}

Awaitable XHR

See http module.

import { ICancellationToken, sendRequest } from "tasklike-promise-library";

async function fetchStatus(ct?: ICancellationToken) {
    const response = await sendRequest({ url: "/api/v1/status", method: "GET" }, ct);
    response.ensureSuccessfulStatusCode();
    const root: IStatusRoot = JSON.parse(response.xhr.responseText);
    return root.status;
}

Awaitable setTimeout/requestAnimationFrame/requestIdleCallback with callback context

See delayedcallbacks module.

The notable benefit is that you can now write the animation in a while loop inside the same async function, and use await to switch context.

import { ICancellationToken, requestAnimationFrameAsync } from "tasklike-promise-library";

async function playAnimation(cancellationToken?: ICancellationToken): Promise<void> {
    cancellationToken && cancellationToken.throwIfCancellationRequested();
    let prevTime = performance.now();
    let currentWidth = 0;
    const panel = document.querySelector("div.panel");
    while (!cancellationToken || !cancellationToken.isCancellationRequested) {
        const animationFrame = await requestAnimationFrameAsync(cancellationToken);
        // From now on, we are inside RAF callback.
        // `animationFrame` contains the information passed from RAF callback,
        // basically, the start time of the animation frame.
        // Make some animation here.
        const frameDuration = animationFrame.time - prevTime;
        // Let the width of .panel increase by 10 pixel/sec.
        currentWidth += frameDuration * 10 * frameDuration / 1000;
        panel.styles.with = Math.round(currentWidth) + "px";
        prevTime = animationFrame.time;
        // End of RAF callback.
        // (More precisely, the callback stop at the next `await requestAnimationFrameAsync` expression.)
    }
}

Build and test

You will need yarn and PowerShell Core pwsh to build this repository properly.

# in repository root
PS /> yarn install
# build repository
PS /> yarn run build
PS /> cd sample
# starts a sample HTTP page on localhost
PS /sample> yarn run start
PS /sample> cd ../packages/tasklike-promise-library
# start tsc watch
PS /packages/tasklike-promise-library> yarn run watch

[TODO: Set up unit test framework.]