Gathering detailed insights and metrics for wdeasync
Gathering detailed insights and metrics for wdeasync
Gathering detailed insights and metrics for wdeasync
Gathering detailed insights and metrics for wdeasync
Turns async function into sync via JavaScript wrapper of Node event loop
npm install wdeasync
Typescript
Module System
Min. Node Version
Node Version
NPM Version
21.9
Supply Chain
74.7
Quality
70.4
Maintenance
100
Vulnerability
97
License
JavaScript (41.3%)
Scheme (34.57%)
Python (15.23%)
C++ (8.91%)
Total Downloads
2,901,985
Last Day
194
Last Week
1,170
Last Month
2,919
Last Year
34,299
MIT License
2 Stars
357 Commits
2 Forks
1 Watchers
2 Branches
2 Contributors
Updated on May 17, 2025
Minified
Minified + Gzipped
Latest Version
0.1.120
Package Id
wdeasync@0.1.120
Unpacked Size
11.40 kB
Size
5.08 kB
File Count
8
NPM Version
10.2.4
Node Version
20.11.0
Published on
Apr 25, 2024
Cumulative downloads
Total Downloads
Last Day
9,600%
194
Compared to previous day
Last Week
160%
1,170
Compared to previous week
Last Month
-50.9%
2,919
Compared to previous month
Last Year
-90.7%
34,299
Compared to previous year
4
2
Deasync turns async function into sync, implemented with a blocking mechanism by calling Node.js event loop at JavaScript layer. The core of deasync is writen in C++.
This fork is created to provide prebuild versions of the library. Original repository
Suppose you maintain a library that exposes a function getData
. Your users call it to get actual data:
var myData = getData();
Under the hood data is saved in a file so you implemented getData
using Node.js built-in fs.readFileSync
. It's obvious both getData
and fs.readFileSync
are sync functions. One day you were told to switch the underlying data source to a repo such as MongoDB which can only be accessed asynchronously. You were also told to avoid pissing off your users, getData
API cannot be changed to return merely a promise or demand a callback parameter. How do you meet both requirements?
You may tempted to use node-fibers or a module derived from it, but node fibers can only wrap async function call into a sync function inside a fiber. In the case above you cannot assume all callers are inside fibers. On the other hand, if you start a fiber in getData
then getData
itself will still return immediately without waiting for the async call result. For similar reason ES6 generators introduced in Node v0.11 won't work either.
What really needed is a way to block subsequent JavaScript from running without blocking entire thread by yielding to allow other events in the event loop to be handled. Ideally the blockage is removed as soon as the result of async function is available. A less ideal but often acceptable alternative is a sleep
function which you can use to implement the blockage like while( !done ) sleep( 100 );
. It is less ideal because sleep duration has to be guessed. It is important the sleep
function not only shouldn't block entire thread, but also shouldn't incur busy wait that pegs the CPU to 100%.
DeAsync supports both alternatives.
Generic wrapper of async function with conventional API signature function( p1, ...pn, function cb( error, result ){ } )
. Returns result
and throws error
as exception if not null:
1var wdeasync = require( 'wdeasync' ); 2var cp = require( 'child_process' ); 3var exec = wdeasync( cp.exec ); 4// output result of ls -la 5try 6{ 7 console.log(exec('ls -la')); 8} 9catch( err ) 10{ 11 console.log( err ); 12} 13// done is printed last, as supposed, with cp.exec wrapped in wdeasync; first without. 14console.log( 'done' );
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
1var done = false; 2var data; 3asyncFunction(p1,function cb(res) 4{ 5 data = res; 6 done = true; 7}); 8require( 'wdeasync' ).loopWhile( function(){ return !done; } ); 9// data is now populated
Sleep (a wrapper of setTimeout)
1function SyncFunction() 2{ 3 var ret; 4 setTimeout(function() 5 { 6 ret = "hello"; 7 },3000); 8 while(ret === undefined) 9 { 10 require( 'wdeasync' ).sleep(100); 11 } 12 // returns hello with sleep; undefined without 13 return ret; 14}
Unlike original implementation, this has binary distributed, so C++ compiler is not mandatory requirement. Altought, rare OS + CPU combinations might require to recompile wdeasync
.
To install, run
npm install wdeasync
Unlike other (a)sync js packages that mostly have only syntactic impact, DeAsync also changes code execution sequence. As such, it is intended to solve niche cases like the above one. If all you are facing is syntatic 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
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
project is archived
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
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
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