Socket
Socket
Sign inDemoInstall

node-callback-style-wrapper

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-callback-style-wrapper

Promise wrapper for callback style code


Version published
Weekly downloads
6
Maintainers
1
Created
Weekly downloads
 

Readme

Source

node-callback-style-wrapper

npm version

Node callback style (also know as error first callback) was great, it arrived as the perfect match with the idea of creating non-blocking software, the win of callbacks over event handlers was instrumental in the growth of modern JS development.

Nowadays the solution is too coupled with the imperative programming paradigm, in 2017 we want to write more declarative code, we don't want to add if statements to check if our callback threw an error.

Promises came to rescue us from the callback nightmare!

The best way to write this declarative code is to use promises, promises belong to the 3rd generation of async programming and they represent the eventual result of an asynchronous operation.

This small module is just a Promisse wrapper for your callbacks.

Install

yarn add -D node-callback-style-wrapper

Example of Usage

const wrapper = require('node-callback-style-wrapper');
const fs = require('fs');

wrapper(fs.readdir, './path/to/my/dir')
   .then((x) => { doStuff(x) })
   .catch((err) => { console.error("Unexpected error", err) })
   

Keywords

FAQs

Last updated on 30 Apr 2017

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