Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

callback-ops

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callback-ops

Callback wrappers

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Callback ops

Just a few callback wrappers to abstract out common result or error wrangling code.

Installation

npm install callback-ops

Usage

var co = require('callback-ops');

return(results..., callback)

Alias: result.

Overwrites return value(s) passed to a callback. Errors are propagated unchanged.

function insertLinks(links, callback) {
    // Create query
    var query = db.insert('link', links);
    // Run query, but ignore its result, pass number or links inserted instead
    query.run(co.return(links.length, callback));
}

Can be used to completely strip results:

// Run query, but don't pass it result to callback
query.run(co.return(callback));

select(keys..., callback)

Select part of result passed to callback. keys could be strings for object properties or numbers for array indexes.

// Pass func2 result to callback
async.serial([func1, func2, func3], co.select(1, callback))

// Select .rows[0].name from result before passing to callback
client.query('select name from user', [],
    co.select('rows', 0, 'name', callback))

fallback(defaultValue, callback)

Passes default to callback instead of error.

Keywords

async

FAQs

Package last updated on 20 Oct 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