Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@kaciras/deasync
Advanced tools
Readme
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.
[!WARNING]
Due to
uv_run()
is not reentrant,awaitSync
and deasynced functions only work on top level, calling them from a callback will cause a deadlock.
npm 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 exports only two APIs: deasync
for callback-style functions, and awaitSync
for Promises.
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):
const { deasync } = require("@kaciras/deasync");
const sleep = deasync((timeout, callback) => {
setTimeout(() => callback(null, "wake up!"), timeout);
});
console.log("Timestamp before: " + performance.now());
console.log(sleep(1000));
console.log("Timestamp after: " + performance.now());
awaitSync(promise)
Similar with the keyword await
but synchronously.
const { awaitSync } = require("@kaciras/deasync");
const { performance } = require("perf_hooks");
const promise = new Promise(resolve => setTimeout(resolve, 1000)).then(() => "wake up!")
console.log("Timestamp before: " + performance.now());
console.log(awaitSync(promise));
console.log("Timestamp after: " + performance.now());
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 syntactic problem such as callback hell, using a less drastic package implemented in pure js is recommended.
FAQs
Turns async code into sync via JavaScript wrapper of Node event loop, support both callback and promise
The npm package @kaciras/deasync receives a total of 1,757 weekly downloads. As such, @kaciras/deasync popularity was classified as popular.
We found that @kaciras/deasync demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.