# exclusively

> Calls fetch() or other async functions exclusively.

Latest version **3.0.2** (published 2022-10-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install exclusively
pnpm add exclusively
yarn add exclusively
bun add exclusively
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2022-10-13 |
| First published | 2022-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | MegPunyu |
| Maintainers | megpunyu |
| Keywords | fetch, async, exclusively |

## Links

- npm: https://www.npmjs.com/package/exclusively
- Repository: https://github.com/MegPunyu/exclusively
- Homepage: https://github.com/MegPunyu/exclusively#readme
- Issues: https://github.com/MegPunyu/exclusively/issues
- npm.io page: https://npm.io/package/exclusively

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 3.0.2 (latest) — 2022-10-13
- 3.0.1 — 2022-10-13
- 3.0.0 — 2022-10-10
- 2.0.0 — 2022-10-10

## README

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

## Features
Calls `fetch()` or other async functions exclusively.

## Installation
```shell
npm install exclusively
```

## Usage
### fetch resources sequentially
```javascript
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
```javascript
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
```javascript
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
```javascript
import Exclusively from "exclusively";

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

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

### multiple contexts
```javascript
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](https://www.npmjs.com/package/node-fetch).
```shell
npm install node-fetch
```

Then, import `fetch()` and set it as a member of `globalThis`.
```javascript
import fetch from "node-fetch";
import Exclusively from "exclusively";

globalThis.fetch = fetch;
```

---
_Source: https://npm.io/package/exclusively · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
