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

@allnulled/asynchandler

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@allnulled/asynchandler

Callback adapter to use in a Promise.

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

asynchandler

Callback adapter to use in a Promise.

Why

To adapt callbacks paradigm to promises paradigm in a nutshel.

Installation

$ npm i -s @allnulled/asynchandler

Usage

This example demonstrates how to use asynchandler with the node fs native module to read and write files using the asynchronous API:

const asynchandler = require("@allnulled/asynchandler");

const example = async function() {
	await new Promise((ok, fail) => {
		fs.writeFile("file.txt", "Contents of the file", "utf8", asynchandler(ok, fail));
	});
	await new Promise(function(ok, fail) {
		fs.readFile("file.txt", "utf8", asynchandler(ok, fail));
	});
};

example();

Source code

The source code of this module is very simple:

module.exports = function(ok, fail) {
	return function(error, data) {
		if (error) {
			fail(error);
			return;
		}
		ok(data);
		return;
	}
};

License

This project is released under WTFPL or What The Fuck Public License. Do what you want.

Keywords

FAQs

Package last updated on 08 Jun 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

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