fast-defer
is a fast and minimal deferred implementation for javascript
Installing
Node
npm install --save fast-defer
yarn add fast-defer
const { deferred, isDeferred } = require('fast-defer');
import { deferred, isDeferred } from 'fast-defer';
Browser
<script crossorigin src="https://unpkg.com/fast-defer@1.0.0"></script>
const { deferred, isDeferred } = window;
Table of contents
Getting Started
Fast defer is nothing more than a promise that you can resolve or reject later.
import { deferred, isDeferred } from 'fast-defer';
const waitingSomething = deferred();
waitingSomething.then((val) => {
console.log('2) Resolved');
});
waitingSomething.catch((error) => {
console.log('2) Rejected');
});
someCallback((response, error) => {
if (error) {
waitingSomething.reject(error);
} else {
waitingSomething.resolve(response);
}
});
License
Licensed under the MIT. See LICENSE
for more informations.
Contact
See my contact information on my github profile or
open a new issue.