sync-promise-js
v1.0.0
Published
An efficient, complete promise implementation with synchronous promise resolution.
Downloads
2
Maintainers
Readme
sync-promise-js
An efficient, complete promise implementation with synchronous promise resolution.
SyncPromise is compliant with the Promise/A+ spec, except part 2.2.4.
Why
Why synchronous promise resolution can be useful:
- Some APIs such as various clipboard operations in browsers still expect synchronous handling.
- Synchronous operations can be faster than operations that require a new execution context.
There exist some similar libraries, but they don't offer the same, complete promise API as this library:
Installation
Assuming you are using a package manager such as npm or Yarn, just install this package from the npm repository:
npm install sync-promise-js
Then you can import SyncPromise
in your JavaScript code:
import SyncPromise from 'sync-promise-js';
Example
SyncPromise.race([
SyncPromise.resolve('sync'),
SyncPromise.delay(100).then(() => 'async')
]).then(result => {
console.log(result);
// will print 'sync' synchronously
});
Usage & Documentation
See the SyncPromise API documentation.
Contributing
Everyone is welcome to contribute. Please read the Contributing agreement and the Development guide for more information, including how to run the tests.
Versioning
We use semantic versioning for this library and its API.
See the changelog for details about the changes in each release.