
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
async-args
Advanced tools
#async-args
A utility for use in conjunction with async or similar libraries to help with passing and storing arguments between asynchronous functions.
Inspiration comes from:
This utility aspires to facilitate the following goals:
The disadvantage to these goals, similar to a microservices architecture, is that it pushes complexity to the integration layer. This library is intended to help manage that complexity.
Think of async-args as a collection of factory functions which produce async functions to replace, select, or insert arguments. You can explore an interactive code example here.
Instance Usage
The same static methods as above are available, in addition to the following:
The static library is returned from the require statement
AsyncArgs = require('async-args')
The following methods are available:
###AsyncArgs.constants([constant], [constant], ...)
Pass constants as arguments to the adjoining function. Arguments from the preceding function are omitted. This method is equivalent to async.constant.
async.waterfall([
AsyncArgs.constants('arg1'), // (next)
aFunctionTakingOneArg // (arg1, next)
], next)
###AsyncArgs.appendConstants([constant], [constant], ...)
Append constants to the arguments coming from the preceding function.
async.waterfall([
outputArg1, // (next)
AsyncArgs.appendConstants('arg2'), // (arg1, next)
aFunctionTakingTwoArgs // (arg1, arg2, next)
], next)
###AsyncArgs.prependConstants([constant], [constant], ...)
Prepend constants to the arguments coming from the preceding function
async.waterfall([
outputArg1, // (next)
AsyncArgs.prependConstants('arg2'), // (arg1, next)
aFunctionTakingTwoArgs // (arg2, arg1, next)
], next)
###AsyncArgs.select([selector], [selector], ...])
selector: boolean or JSON Pointer
Select a subset of arguments coming from the preceding function.
async.waterfall([
outputArg1Arg2Arg3, // (next)
AsyncArgs.select(false, false, true), // (arg1, arg2, arg3, next)
aFunctionTakingOneArg // (arg3, next)
], next)
A JSON Pointer can be used to select an array item or object property from an argument
var constant = {a:{b:['c','d']}}
async.waterfall([
AsyncArgs.constants(constant, constant), // (next)
AsyncArgs.select('/a/b/1', /a/b/0'), // (constant, constant, next)
aFunctionTakingOneArg // ('d', 'c', next)
], next)
An instance is returned by calling the static library, which allows the storing and retrieving of values from a context object.
var asyncArgs = AsyncArgs()
You can prepopulate the context object when the instance is first created:
var context = {
'key1': 'value1',
'key2': 'value2'
}
var asyncArgs = AsyncArgs(context)
This context object is updated in place (no copy is made), so if you want synchronous access to these values, follow this example to reference the context for later use.
The same static methods as above are available, along with the following methods unique to instances:
###asyncArgs.store([key1], [key2], ...)
Store selected arguments coming from the previous function to the context object. Arguments from the preceding function pass through.
async.waterfall([
outputArg1Arg2Arg3, // (next)
asyncArgs.store('arg1', 'arg2', 'arg3'), // (arg1, arg2, arg3, next)
aFunctionTakingThreeArgs // (arg1, arg2, arg3, next)
], next)
###asyncArgs.values([key1], [key2], ...)
Pull specific values from the context object and pass as arguments to the adjoining function. Arguments from the preceding function are omitted.
async.waterfall([
outputArg1Arg2Arg3, // (next)
asyncArgs.store('arg1', 'arg2', 'arg3'), // (arg1, arg2, arg3, next)
aFunctionTakingThreeArgsAndOutputArg4, // (arg1, arg2, arg3, next)
asyncArgs.values('arg2'), // (arg4, next)
aFunctionTakingOneArg // (arg2, next)
], next)
###asyncArgs.appendValues([key1], [key2], ...)
Pull specific values from the context object and append to the arguments coming from the preceding function.
async.waterfall([
outputArg1Arg2Arg3, // (next)
asyncArgs.store('arg1', 'arg2', 'arg3'), // (arg1, arg2, arg3, next)
aFunctionTakingThreeArgsAndOutputArg4, // (arg1, arg2, arg3, next)
asyncArgs.appendValues('arg2'), // (arg4, next)
aFunctionTakingOneArg // (arg4, arg2, next)
], next)
###asyncArgs.prependValues([key1], [key2], ...)
Pull specific values from the context object and prepend to the arguments coming from the preceding function.
async.waterfall([
outputArg1Arg2Arg3, // (next)
asyncArgs.store('arg1', 'arg2', 'arg3'), // (arg1, arg2, arg3, next)
aFunctionTakingThreeArgsAndOutputArg4, // (arg1, arg2, arg3, next)
asyncArgs.prependValues('arg2'), // (arg4, next)
aFunctionTakingOneArg // (arg2, arg4, next)
], next)
FAQs
A utility for use in conjunction with async.
The npm package async-args receives a total of 4 weekly downloads. As such, async-args popularity was classified as not popular.
We found that async-args demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.