🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

make-synchronous

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

make-synchronous

Make an asynchronous function synchronous

0.1.0
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

make-synchronous Build Status

Make an asynchronous function synchronous

This is the wrong tool for most tasks! Prefer using 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 subprocess.

Works in Node.js only, not the browser.

Install

$ npm install make-synchronous

Usage

const makeSynchronous = require('make-synchronous');

const fn = makeSynchronous(async number => {
	const delay = require('delay');

	await delay(100);

	return number * 2;
});

console.log(fn(2));
//=> 4

API

makeSynchronous(asyncFunction)

Returns a wrapped version of the given async function which executes synchronously. This means no other code will execute (not even async code) until the given async function is done.

The given function is executed in a subprocess, so you cannot use any variables/imports from outside the scope of the function. You can pass in arguments to the function. To import dependencies, use either require(…) or await import(…) in the function body.

It uses the V8 serialization API transfer arguments, return values, errors between the subprocess and the current process. It supports most values, but not functions and symbols.

  • sleep-synchronously - Block the main thread for a given amount of time

Keywords

function

FAQs

Package last updated on 18 Aug 2020

Did you know?

Socket

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.

Install

Related posts