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

exclusively

v3.0.2

Published

Calls fetch() or other async functions exclusively.

Downloads

3

Readme

Exclusively

Exclusively is a simple class that provides methods for executing async functions exclusively.

Features

Calls fetch() or other async functions exclusively.

Installation

npm install exclusively

Usage

fetch resources sequentially

import Exclusively from "exclusively";

const request = new Request("https://example.com/");

/* JavaScript fetch() function */

                 // Network waterfall (example)
fetch(request);  // |----|
fetch(request);  // |-------|
fetch(request);  // |--|


/* Exclusively fetch() method */
const context = new Exclusively();

                         // Network waterfall (example)
context.fetch(request);  // |---|
context.fetch(request);  //     |-----|
context.fetch(request);  //           |----|

call async functions sequentially

import Exclusively from "exclusively";

const wait3s = async () => new Promise(resolve => setTimeout(() => {
    console.log("3s");
    resolve();
}, 3000));

/* print "3s" three times every three seconds. */
const context = new Exclusively();

                       // execution time
context.exec(wait3s);  // |---|
context.exec(wait3s);  //     |---|
context.exec(wait3s);  //         |---|

share "Exclusively" instance among multiple script files

sample1.js

import Exclusively from "exclusively";

const context = Exclusively.getContext("sample");  // get context named "sample" (if it does not exist, it will be created)

context.fetch("https://example.com/");

sample2.js

import Exclusively from "exclusively";

const context = Exclusively.getContext("sample");  // same object as "const context" in sample1.js

context.fetch("https://example.com/");

multiple contexts

import Exclusively from "exclusively";

const request = new Request("https://example.com/");

const context1 = new Exclusively();
const context2 = new Exclusively();

                          // Network waterfall (example)
context1.fetch(request);  // |---|
context2.fetch(request);  // |----|
context1.fetch(request);  //     |----|
context2.fetch(request);  //      |--|
context1.fetch(request);  //          |----|
context2.fetch(request);  //         |----|

globalThis.fetch

Exclusively.prototype.fetch() calls globalThis.fetch() internally. The Fetch API has been available by default since Node.js 18, but for earlier versions, globalThis.fetch() must be defined in some way. One of the ways is to install node-fetch.

npm install node-fetch

Then, import fetch() and set it as a member of globalThis.

import fetch from "node-fetch";
import Exclusively from "exclusively";

globalThis.fetch = fetch;