Socket
Book a DemoInstallSign in
Socket

resolver-macro

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

resolver-macro

A sweet.js macro for creating a promise-resolving function.

0.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

resolver-macro

This sweet.js macro will help you turn any standard callback-based function into a promise, using whichever promise library you want.

Example

Here's an example using when and the standard fs.readFile command:

when.promise( resolver(fs.readFile, 'hello_world.txt', {encoding: 'utf-8'}) );

Getting Started

To use the macro, take a look at the sweet.js project, or setup a grunt task using something like grunt-sweet.js. You can then just install this module and require it when running sweet.js.

If you are totally new to macros, I recommend reading this excellent article:

Writing Your First Sweet.js Macro by James Long

Usage

The resolver macro will match the following pattern:

resolver(FUNCITON, ARGS...)

And expand it to:

function(resolve, reject, notify) {
  FUNCTION(ARGS..., function(err, result) {
    if (err) {
      reject(err);
    }
    resolve(result);
  }
}

This allows you to wrap that resolver function in any promise library you want. It will take any arguments in ARGS... and pass them to FUNCTION, and then add on the callback handling function for you.

Keywords

sweet.js

FAQs

Package last updated on 26 Feb 2014

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.