
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Asynk is a feature-rich JavaScript library designed to simplify common asynchronous JavaScript programming tasks.
Asynk is a feature-rich JavaScript library designed to simplify common asynchronous JavaScript programming tasks.
asynk.add(fs.open).args('./TEST.txt','w',asynk.callback)
.add(fs.write).args(asynk.data(0),new Buffer('hello world'),0,11,null,asynk.callback)
.add(fs.close).args(asynk.data(-2),asynk.callback)
.add(fs.readFile).args('./TEST.txt', "utf8",asynk.callback).alias('content')
.serie([asynk.data('content')]).done(console.log);
//Log 'hello world' in console
Asynk adapt to fit your functions syntax without writting a warper function and can dynamically get results from a task output back to an other input and more... see full documentation below.
Install from NPM.
$ npm install asynk
MIT
Asynk command must start by adding one or more task using functions:
add(fct)
add one task
arguments:
asynk.add(my_function).args(my_first_argument,asynk.callback) //...
this make asynk create a manager with one task
each(array_data,fct)
add a task per array's item of the same function
arguments:
asynk.each([0,1,2],my_function).args(asynk.item,asynk.callback) //...
this make asynk create a manager with tree tasks(asynk.item is on value of the array in input) witch is the equivalent of:
asynk.add(my_function).args(0,asynk.callback)
.add(my_function).args(1,asynk.callback)
.add(my_function).args(2,asynk.callback) //...
args(arg1,arg2,...)
arguments:
the args function define arguments of function passed to the task. simply pass arguments like executing the function and replace the callback function by asynk.callback
asynk.add(my_function).args(0,asynk.callback) //...
will execute the function like this :
function callback(err,data){
//the callback function
}
my_function(0,callback); //...
asynk.data(task)
data put output of a task to the input of another one.
arguments:
//create a first task
asynk.add(my_function).args(0,asynk.callback)
//absolute position task data (here first one)
.add(my_function).args(asynk.data(0),asynk.callback)
//relative position task data (here the second one)
.add(my_function).args(asynk.data(-1),asynk.callback)
//assinging an alias name to this task
.add(my_function).args(0,asynk.callback).alias('here')
//alias name task data (here the fourth)
.add(my_function).args(asynk.data('here'),asynk.callback)
//...
require(dependency)
require function make task waiting an other one to finish before start.
arguments:
//create a first task
asynk.add(my_function0).args(0,asynk.callback)
//alias name task requirement (here the fifth)
.add(my_function1).args(4,asynk.callback).require('here')
//absolute position task requirement (here the fifth)
.add(my_function2).args(1,asynk.callback).require(4)
//relative position task requirement (here the third)
.add(my_function3).args(2,asynk.callback).require(-1)
//assinging an alias name to this task
.add(my_function4).args(3,asynk.callback).alias('here')
//...
here my_function0 and my_function4 will be execute first. then on my_function4's end,my_function1 and my_function2 will be execute. and so on my_function2's end,my_function3 will be execute.
Asynk command must finnish by choosing an excution mode:
serie(args)
arguments:
return: a promise
in this mode,all task are execute one by one in the order they where inserted.
asynk.each(['one','two'],my_function).args(asynk.item,asynk.callback)
.serie().done(console.log);
here my_function is called with argument 'one',once this function ended,the same function is called with argument 'two'. when every task are finnished,the function passed to serie is called with args arguments array.
parallel(args)
arguments:
return: a promise
in this mode,all task are started at the same time.
asynk.each(['one','two'],my_function).args(asynk.item,asynk.callback)
.parallel().done(console.log);
here my_function is called with argument 'one' and a second time with 'two' without waiting anything. when every task are finnished,the function passed to parallel is called with args arguments array.
parallelLimited(limit,args)
arguments:
return: a promise
in this mode,a predefined number(limit) of task are running in the same time.
asynk.each([0,0,0,0],my_function).args(asynk.item,asynk.callback)
.parallelLimited(2).done(console.log);
here my_function is called four time with 0 as argument but two time before and one time after a callback is called until all four tasks are done. when every task are finnished,the function passed to parallelLimited is called with args arguments array.
asynk.deferred()
A factory function that returns a chainable utility object with methods to register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.
return: a deferred object
var deferred = asynk.deferred();
var promise = deferred.promise();
promise.done(function(arg){
console.log('hello ' + arg);
});
deferred.resolve('world');
always(fct)
Add function to be called when the deferred object is either resolved or rejected.
arguments:
return: the deferred/promise object
done(fct)
Add function to be called when the deferred object is resolved.
arguments:
return: the deferred/promise object
fail(fct)
Add function to be called when the deferred object is rejected.
arguments:
return: the deferred/promise object
isRejected()
Determine whether a deferred object has been rejected.
return: a boolean
isResolved()
Determine whether a deferred object has been resolved.
return: a boolean
notify(args)
Call the progressCallbacks on a deferred object with the given args.
arguments:
return: the deferred object
notifyWith(context, args)
Call the progressCallbacks on a deferred object with the given context and args.
arguments:
this
object.return: the deferred object
pipe(doneFilter)
Utility method to filter and/or chain deferreds.
arguments: *doneFilter: A function called as doneCallback that return is passed to pipe returned promise doneCallbacks as arguments.
return: a promise object
progress(fct)
Add function to be called when the deferred object generates progress notifications.
arguments:
return: the deferred/promise object
promise(obj)
Return a deferred’s Promise object.
arguments:
return: a promise object
reject(args)
Reject a deferred object and call any failCallbacks with the given args.
arguments:
return: the deferred/promise object
rejectWith(context, args)
Reject a deferred object and call any failCallbacks with the given context and args.
arguments:
this
object.return: the deferred object
resolve(args)
Resolve a deferred object and call any doneCallbacks with the given args.
arguments:
return: the deferred/promise object
resolveWith(context, args)
Resolve a deferred object and call any doneCallbacks with the given context and args.
arguments:
this
object.return: the deferred object
state()
Determine the current state of a deferred object.
return: a string('pending','resolved' or 'rejected')
then(doneFilter, failFilter, progressFilter)
Add functions to be called when the deferred object is resolved, rejected, or still in progress.
arguments:
return: a promise object
when(deferreds)
Provides a way to execute callbacks functions based on one or more deferred objects that represent asynchronous events.
arguments:
return: a promise object
first pushed function are first executed
create a fifo stack object:
var fifo = asynk.fifo();
push(fct) arguments:
return a function that take fct arguments as arguments
var result = '';
var fifo = asynk.fifo();
var f1 = fifo.push(function(err,data){result += data;});
var f2 = fifo.push(function(err,data){result += data;});
var f3 = fifo.push(function(err,data){result += data;});
var f4 = fifo.push(function(err,data){result += data;});
var f5 = fifo.push(function(err,data){result += data;});
var f6 = fifo.push(function(err,data){result += data;});
f6(null,6);
f2(null,2);
f4(null,4);
f1(null,1);
f3(null,3);
f5(null,5);
console.log(result); //123456
function are executed in a predefined order
create a progressive stack object:
var progr = asynk.progressive(start,step);
arguments:
push(order,fct) arguments:
var result = '';
var progr = asynk.progressive();
progr.push(6,function(err,data){result += data;})(null,6);
progr.push(2,function(err,data){result += data;})(null,2);
progr.push(4,function(err,data){result += data;})(null,4);
progr.push(1,function(err,data){result += data;})(null,1);
progr.push(3,function(err,data){result += data;})(null,3);
progr.push(5,function(err,data){result += data;})(null,5);
console.log(result); //123456
FAQs
Asynk is a feature-rich JavaScript library designed to simplify common asynchronous JavaScript programming tasks.
The npm package asynk receives a total of 89 weekly downloads. As such, asynk popularity was classified as not popular.
We found that asynk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.