prutill
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

GitHub version Coverage Status dependency status contributions welcome

What is it?

Not React.js only Promise utilities to improve multiple Promise processing.

The orignal inspiration went from the issue in React.js application I had, where the useEffect watched multiple variables triggered multiple promises which each of one ran then action. If latest promise has been quicker, the earlier less relevant had main effect upon the application state.

Ready to be used in Deno and Node.js. To see more details how to use it, please check related unit tests in ./src/*.spec.ts and tests in ./tests folder.

Deno example

deno test https://raw.githubusercontent.com/dominikj111/prutill/main/tests/deno.test.ts or

deno test https://raw.githubusercontent.com/dominikj111/prutill/main/tests/deno.test.js

How to get it on Node.js or Bun

npm i prutill, bun add prutill

bun test doesn't work as expected with this library as there are Deno tests included and timedPromise.spec.ts also doesn't pass due to bun/issues/3594.

Problems to solve

As a develoer, I want:

  • To make multiple promises, but act on latestly added only.
import { getLastPromise } from "prutill";

...

React.useEffect(() => {
    getLastPromise("my_data_processing_promise_stack", /* Promise, fetch or anything what returns promise */).then(data => {
        // Do something with data from last promise/update
    });
}, [ state.var_1, state.var_2, state.var_3 ]);

...
  • To make multiple promises, but act on the quickest one.
import { getRaceWonPromise } from "prutill";

...

React.useEffect(() => {
    getRaceWonPromise("my_data_processing_promise_race", fetch(...) /* Promise, fetch or anything what returns promise */).then(data => {
        // Do something with data from first resolved promise/update
    });
}, [ state.var_1, state.var_2, state.var_3 ]);

...
  • To get the resolved promise after spicific time.
import { TimedPromise } from "prutill";

new TimedPromise(500).then(r => r === 500);

Possible improvements when requested

🔲 Add bundling to import from CDN (vanilla js) -> umd, esm

🔲 Improve Continuous Integration

🔲 Add Changelog, Code of Conduct

🔲 Automatic testing and linting

Package Sidebar

Install

npm i prutill

Weekly Downloads

1

Version

1.0.3

License

Apache-2.0

Unpacked Size

51.7 kB

Total Files

37

Last publish

Collaborators

  • domino2