Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deasync

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deasync

Turns async function into sync via JavaScript wrapper of Node event loop

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
495K
increased by5.82%
Maintainers
1
Weekly downloads
 
Created

What is deasync?

The deasync npm package allows you to convert asynchronous functions into synchronous ones. This can be useful in scenarios where you need to perform asynchronous operations in a synchronous manner, such as during initialization or configuration phases.

What are deasync's main functionalities?

Convert Asynchronous Function to Synchronous

This feature allows you to convert an asynchronous function into a synchronous one. The code demonstrates how to use deasync to wait for an asynchronous function to complete before proceeding.

const deasync = require('deasync');
let done = false;
let result;
asyncFunction((err, res) => {
  if (err) throw err;
  result = res;
  done = true;
});
while (!done) {
  deasync.sleep(100);
}
console.log(result);

Sleep Function

The sleep function pauses the execution of code for a specified number of milliseconds. This can be useful for delaying operations or simulating long-running tasks.

const deasync = require('deasync');
console.log('Start');
deasync.sleep(2000);
console.log('End');

Synchronous Read File

This feature demonstrates how to read a file synchronously using deasync. The code waits for the asynchronous readFile operation to complete before proceeding.

const fs = require('fs');
const deasync = require('deasync');
let content;
fs.readFile('example.txt', 'utf8', (err, data) => {
  if (err) throw err;
  content = data;
  done = true;
});
while (!done) {
  deasync.sleep(100);
}
console.log(content);

Other packages similar to deasync

Keywords

FAQs

Package last updated on 08 Feb 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc