Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Yaku is a lightweight and fast Promise library that is fully compatible with ES6 Promises. It aims to provide better performance and smaller size compared to native Promises and other Promise libraries.
Basic Promise Usage
This demonstrates the basic usage of Yaku to create a new Promise and handle its resolution.
const Yaku = require('yaku');
const promise = new Yaku((resolve, reject) => {
setTimeout(() => resolve('Hello, Yaku!'), 1000);
});
promise.then(value => console.log(value));
Chaining Promises
This demonstrates how to chain multiple `then` calls to handle the resolved value step by step.
const Yaku = require('yaku');
const promise = new Yaku((resolve, reject) => {
setTimeout(() => resolve(1), 1000);
});
promise
.then(value => value + 1)
.then(value => value * 2)
.then(value => console.log(value));
Error Handling
This demonstrates how to handle errors in Yaku Promises using the `catch` method.
const Yaku = require('yaku');
const promise = new Yaku((resolve, reject) => {
setTimeout(() => reject(new Error('Something went wrong')), 1000);
});
promise
.then(value => console.log(value))
.catch(error => console.error(error.message));
Promise.all
This demonstrates how to use `Yaku.all` to wait for multiple Promises to resolve.
const Yaku = require('yaku');
const promise1 = Yaku.resolve(1);
const promise2 = Yaku.resolve(2);
const promise3 = Yaku.resolve(3);
Yaku.all([promise1, promise2, promise3])
.then(values => console.log(values));
Bluebird is a fully featured Promise library with a focus on performance and additional features not found in native Promises. It offers more utility methods and better error handling compared to Yaku, but it is larger in size.
Q is another Promise library that provides a lot of additional functionality such as deferred objects and more advanced control flow. It is more feature-rich compared to Yaku but also comes with a larger footprint.
When is a lightweight Promise library that focuses on performance and small size, similar to Yaku. It provides a few more utilities for working with Promises but is generally comparable in terms of performance and size.
The src/yaku.coffee
of Yaku is full compatible with V8's native Promise, but much faster.
If you want to learn how Promise works, read the minimum implementation docs/minPromiseA+.coffee. Without comments, it is only 80 lines of code.
It only implements the constructor
and then
. It passed all the tests of promises-aplus-tests.
I am not a optimization freak, I try to keep the source code readable and maintainable.
npm install yaku
Then:
Promise = require 'yaku'
Download the yaku.js
file from release page. It supports both AMD
and CMD
.
Raw usage without AMD
or CMD
:
<script type="text/javascript" src ="yaku.js"></script>
<script>
// Yaku will be assigned to `window.Yaku`.
Promise = Yaku
</script>
These comparisons only reflect some limited truth, no one is better than than others on all aspects.
iojs v1.8.1
OS darwin
Arch x64
CPU Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
Name | Unit Test | 1ms async task | sync task | Helpers | file size |
---|---|---|---|---|---|
Yaku | 872/872 | 283ms | 68ms | ++ | 2.7KB |
Bluebird | 872/872 | 244ms | 164ms | +++++++ | 73KB |
ES6-promise | 872/872 | 435ms | 110ms | + | 18KB |
native | 872/872 | 816ms | 605ms | + | 0KB |
q | 208/872 | 2637ms | 2327ms | +++ | 24K |
npm run no -- benchmark
, the smaller the better.npm run no -- benchmark --sync
, the smaller the better.Long stack trace support?
Latest Node.js and browsers are already support it. If you enabled it, Yaku will take advantage of it without much overhead. Such as this library longjohn for Node.js, or this article for Chrome.
This project use promises-aplus-tests to test the compliance of Promise/A+ specification. There are about 900 test cases.
Use npm run no -- test
to run the unit test.
Use npm run no -- benchmark
to run the benchmark.
The name yaku
comes from the word 約束(yakusoku)
which means promise.
FAQs
A lightweight promise library
The npm package yaku receives a total of 118,383 weekly downloads. As such, yaku popularity was classified as popular.
We found that yaku demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.