Socket
Socket
Sign inDemoInstall

dezalgo

Package Overview
Dependencies
2
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    dezalgo

Contain async insanity so that the dark pony lord doesn't eat souls


Version published
Weekly downloads
8.2M
increased by1.73%
Maintainers
6
Install size
41.2 kB
Created
Weekly downloads
 

Package description

What is dezalgo?

The dezalgo npm package ensures that a callback is always called asynchronously, and not in the same tick of the event loop that it was added in, even if it is already complete. This is useful for preventing stack overflows and ensuring consistent asynchronous behavior.

What are dezalgo's main functionalities?

Ensuring asynchronous callback execution

This feature wraps a callback function to ensure that it is always called on the next tick of the event loop, even if it could be called immediately.

const dezalgo = require('dezalgo')
const callback = dezalgo((err, data) => {
  // This will always run asynchronously
  console.log('Callback called asynchronously')
})

// Even if we call it synchronously, it will be deferred
callback(null, 'some data')

Other packages similar to dezalgo

Readme

Source

dezalgo

Contain async insanity so that the dark pony lord doesn't eat souls

See this blog post.

USAGE

Pass a callback to dezalgo and it will ensure that it is always called in a future tick, and never in this tick.

var dz = require('dezalgo')

var cache = {}
function maybeSync(arg, cb) {
  cb = dz(cb)

  // this will actually defer to nextTick
  if (cache[arg]) cb(null, cache[arg])

  fs.readFile(arg, function (er, data) {
    // since this is *already* defered, it will call immediately
    if (er) cb(er)
    cb(null, cache[arg] = data)
  })
}

Keywords

FAQs

Last updated on 06 Apr 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc