Gathering detailed insights and metrics for @kaciras/deasync
Gathering detailed insights and metrics for @kaciras/deasync
Gathering detailed insights and metrics for @kaciras/deasync
Gathering detailed insights and metrics for @kaciras/deasync
npm install @kaciras/deasync
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
42 Stars
306 Commits
5 Forks
2 Watching
1 Branches
13 Contributors
Updated on 25 Nov 2024
Minified
Minified + Gzipped
TypeScript (64.58%)
JavaScript (31.52%)
C++ (3.34%)
Python (0.57%)
Cumulative downloads
Total Downloads
Last day
-61.4%
262
Compared to previous day
Last week
-33.8%
2,721
Compared to previous week
Last month
-13.9%
10,377
Compared to previous month
Last year
254.4%
108,930
Compared to previous year
DeAsync turns async code into sync, implemented with a blocking mechanism by calling Node.js event loop at JavaScript layer. The core of deasync is written in C++.
This project is forked from abbr/deasync and rewritten in modern code, adding some new features: types, Promise support, and prebuild binaries.
The benefit of this package over synckit, await-sync and others libs is that this runs your code in the current context, so parameters and the return value of your function are no need to be serializable, you are free to use Symbol
, functions, and objects with prototypes.
[!WARNING]
Due to
uv_run()
is not reentrant, functions that poll the event loop and deasynced functions only work at the top level, and calling them from asynchronous callbacks can lead to deadlocks.
1npm install @kaciras/deasync
DeAsync downloads prebuild binary from GitHub releases during installation, if download fails, try to build locally. You can skip the install phase by setting the environment variable NO_PREBUILD=1
.
DeAsync uses node-gyp to compile C++ source code, so to build Deasync you may need the compilers listed in node-gyp.
deasync(function)
Generic wrapper of async function with conventional API signature function(...args, (error, result) => {})
. Returns result
and throws error
as exception if not null.
Sleep (a wrapper of setTimeout):
1const { deasync } = require("@kaciras/deasync"); 2 3const sleep = deasync((timeout, callback) => { 4 setTimeout(() => callback(null, "wake up!"), timeout); 5}); 6 7console.log("Timestamp before: " + performance.now()); 8console.log(sleep(1000)); 9console.log("Timestamp after: " + performance.now());
awaitSync(promise)
Similar with the keyword await
but synchronously.
1const { awaitSync } = require("@kaciras/deasync"); 2 3const promise = new Promise(resolve => setTimeout(resolve, 1000)).then(() => "wake up!") 4 5console.log("Timestamp before: " + performance.now()); 6console.log(awaitSync(promise)); 7console.log("Timestamp after: " + performance.now());
uvRun()
Run pending callbacks of macro tasks in the event loop.
1const { uvRun } = require("@kaciras/deasync"); 2 3let called = false; 4setImmediate(() => called = true); 5 6uvRun(); 7console.log(`Called is ${called}`); // Called is true
runLoopOnce()
Run micro task callbacks until the queue has been exhausted, then run pending callbacks of macro tasks.
loopWhile(predicate)
For async function with unconventional API, for instance function asyncFunction(p1,function cb(res){}), use loopWhile(predicateFunc) where predicateFunc is a function that returns boolean loop condition.
1let done = false; 2let data; 3asyncFunction(p1, res => { 4 data = res; 5 done = true; 6}); 7require('deasync').loopWhile(() => !done); 8// data is now populated
DeAsync changes code execution sequence and the task scheduling, which typically degrades performance. The primary use case for DeAsync is compatibility with legacy code that does not support asynchronous. If all you are facing is syntactic problem such as callback hell, using a less drastic package implemented in pure js is recommended.
No vulnerabilities found.
Reason
20 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
2 existing vulnerabilities detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More