
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
make-synchronous
Advanced tools
Make an asynchronous function synchronous
This is the wrong tool for most tasks! Prefer async APIs whenever possible.
The benefit of this package over packages like deasync
is that this one is not a native Node.js addon (which comes with a lot of problems). Instead, this package executes the given function synchronously in a worker
or subprocess
.
Works in Node.js only — not the browser.
npm install make-synchronous
Runs in a worker thread by default:
import makeSynchronous from 'make-synchronous';
const fn = makeSynchronous(async number => {
const {default: delay} = await import('delay');
await delay(100);
return number * 2;
});
console.log(fn(2));
//=> 4
To run in a subprocess instead:
import makeSynchronous from 'make-synchronous/subprocess';
makeSynchronous(async () => {
// Runs in a subprocess.
});
Subprocess execution is slower, but has the benefit of full process isolation.
Returns a wrapped version of the given async function or a string representation to a async function which executes synchronously. This means no other code will execute (not even async code) until the given async function is done.
The function is executed in a worker or subprocess, so you cannot access variables or imports from outside its scope. Use await import(…)
to import dependencies inside the function.
Uses MessagePort#postMessage()
or the V8 serialization API to transfer arguments, return values, errors between the worker or subprocess and the current process. Most values are supported — except functions and symbols.
FAQs
Make an asynchronous function synchronous
The npm package make-synchronous receives a total of 37,186 weekly downloads. As such, make-synchronous popularity was classified as popular.
We found that make-synchronous 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.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.