@mostakchif/revocable-promise
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

revocablePromise:

revocablePromise allows you to revoke a promise or an array of promises, and set a minimum time to response.

installation:

npm install @mostakchif/revocable-promise

simple use:

const {RevocablePromise} = require("@mostakchif/revocable-promise");

// init
const q = new RevocablePromise(fetch("http://localhost:8080/users"));

// set a minimum timeout
q.minTimeout = 500;

// revoke the promise and then or catch methods not be calls if they are not already called
q.revoke();

q.then((users) => console.log(users));
q.catch((err) => console.log(err));

/* multi promises */

const qs = new RevocablePromise([
    fetch("http://localhost:8080/users"),
    fetch("http://localhost:8080/tweets"),
]);

qs.minTimeout = 500;

qs.revoke();

qs.then(([users, tweets]) => console.log(users, tweets));
qs.catch((err) => console.log(err));

react example:

class Bar extends React.Component {
    componentDidMount() {
        this.q = new RevocablePromise(fetch("http://localhost:8080/users"));
    }
    
    componentWillUnmount() {
        this.q.revoke();
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @mostakchif/revocable-promise

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

35.8 kB

Total Files

13

Last publish

Collaborators

  • ha-abdou