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
Turns async function into sync via JavaScript wrapper of Node event loop
npm install @kaciras/deasync
Typescript
Module System
Min. Node Version
Node Version
NPM Version
68.6
Supply Chain
100
Quality
76.4
Maintenance
100
Vulnerability
100
License
TypeScript (64.58%)
JavaScript (31.52%)
C++ (3.34%)
Python (0.57%)
Total Downloads
290,561
Last Day
626
Last Week
8,262
Last Month
33,484
Last Year
196,059
MIT License
54 Stars
323 Commits
5 Forks
2 Watchers
1 Branches
13 Contributors
Updated on Jun 15, 2025
Minified
Minified + Gzipped
Latest Version
1.1.0
Package Id
@kaciras/deasync@1.1.0
Unpacked Size
14.72 kB
Size
5.88 kB
File Count
8
NPM Version
10.9.0
Node Version
23.0.0
Published on
Oct 24, 2024
Cumulative downloads
Total Downloads
Last Day
56.1%
626
Compared to previous day
Last Week
0.1%
8,262
Compared to previous week
Last Month
12.6%
33,484
Compared to previous month
Last Year
184.4%
196,059
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 tasks until the micro task queue has been exhausted, then run a macro task (if any).
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
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
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
security policy file not detected
Details
Reason
project is not fuzzed
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 2025-06-30
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