Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
baby-workers
Advanced tools
Execute and manage your code asynchronously with workers, like promise, execute each element of an array or a simple element in callback.
Execute and manage your code asynchronously with workers, like promise, execute each element of an array or a simple element in callback. Like thread, you can start and stop your jober where and when you want in your code. You can limit the number of jobers or execute it like a stack. Do everything asynchronously with baby-workers !
npm install --save baby-workers
Version | Change log | Compatibility |
---|---|---|
2.0.0 | Add map, set, push (data), next, exec, reply and getError functions + fix some bugs | >= 2.0.0 |
2.0.0 beta | Add promise after run/timeout/interval/stack function + add then/catch callback + catch error in run/timeout/interval/stack callback + add feature to create worker without name | >= 2.0.0 |
1.0.71 | Add getNodes function | <= 1.0.71 |
Three entites :
[Root] -> worker.create(...) -> [Parent] -> .map(['...', '...']) or .set(...) -> .run() or .stack() or [...] -> [Node] + [Node]
workers.create('MyWorker', (worker, elem) => {
console.log('|=>', elem);
worker.pop();
}).map(['a', 'b', 'c', 'd']).run().then(() => { // then is a promise
console.log('Then');
}).catch(() => { // catch is a promise
console.log('Catch');
});
workers.create('MyWorker2', (worker, elem) => {
console.log('|=>', elem);
worker.pop();
}).set(['a', 'b', 'c', 'd']).run().then(() => { // then is a promise
console.log('Then');
}).catch(() => { // catch is a promise
console.log('Catch');
});
workers.then(() => { // then is not a promise
console.log('Then');
}).catch(() => { // catch is not a promise
console.log('Catch');
}).complete(() => {
console.log('Complete');
});
Function | Available | Description | Additionnal |
---|---|---|---|
create(name: string or callback: function , callback: function ) : currentWorker | ALL | Create a new parent | |
set(data: any ) : currentWorker | PARENT | Set data and create a new node | |
map(data: array ) : currentWorker | PARENT | Set array and create a new node for each element in the array | |
push(data: any ) : currentWorker | PARENT | Push a new data and create a new node | |
error(error: string ) : currentWorker | ALL | Set error in current worker and all parent in the tree | |
pop() : currentWorker | NODE | Stop current node | |
run() : Promise | PARENT | Create and run nodes |
Function | Available | Description | Additionnal |
---|---|---|---|
stack() : Promise | PARENT | Create and run nodes like a stack | |
next() : Promise | PARENT | Create and run the next node | |
exec(idNode: number ) : Promise | PARENT | Create and run a specific node | |
reply(idNode: number = undefined ) : Promise | PARENT | Reply a node or all nodes if idNode is undefined | |
delay(time: number = 1 ) : Promise | PARENT | Create and run nodes in a timeout | |
interval(time: number = 1000 ) : Promise | PARENT | Create and run nodes in an interval | stop() : currentWorker , NODE, Stop interval |
Function | Available | Description | Additionnal |
---|---|---|---|
cancel() : currentWorker | PARENT | Cancel parent worker | |
limit(maxWorkers: number = 0 , extra: boolean = false ) | ALL | Limit the number of workers (maxWorkers = 0 = unlimited or take limit of parent - maxWorkers = -1 = unlimited and ignore parent). If extra = true is true so maxWorkers is taken ONLY if parent workers limit is full | |
addWorker() : currentWorker | ALL | Add virtual worker (be careful !) | |
removeWorker() : currentWorker | ALL | Remove virtual worker (be careful !) |
Function | Available | Description | Additionnal |
---|---|---|---|
complete(callback: function , removeAfterCall: boolean ) : currentWorker | ALL | Call function when current process is finish (node, parent => when childrens are finish or root => when childrens are finish) | |
then(callback: function , removeAfterCall: boolean ) : currentWorker | ALL | Call function when current process is finish without error | |
catch(callback: function , removeAfterCall: boolean ) : currentWorker | ALL | Call function when current process is finish with error |
Function | Available | Description | Additionnal |
---|---|---|---|
save(data: any ) : currentWorker | ALL | Save any data in current worker (node, parent or root) | |
_save(data: any ) : currentWorker | ALL | Save any data in current worker (node, parent or root) from root | |
get() : any | ALL | Get data previously saved | |
_get() : any | ALL | Get data previously saved from root | |
flux : object | ALL | IS NOT A FUNCTION BUT AN OBJECT ! |
Function | Available | Description | Additionnal |
---|---|---|---|
root() : parentWorker | NODE | Get root/parent of current worker | |
parent(name: string , type: string = 'parent' ) : parentWorker OR nodeWorker | PARENT & NODE | Get any parent/node going up the tree | |
parentNode(name: string ) : parentWorker OR nodeWorker | PARENT & NODE | Get any node going up the tree | |
node(key: number ) : nodeWorker | PARENT | Return a node from parent |
Function | Available | Description | Additionnal |
---|---|---|---|
getId() : number | NODE | Return id/key/index of node | |
getStatus() : string | ALL | Return global status | |
getError : string | ALL | Return error | |
getNodeStatus() : string | NODE | Return the status of node | |
getName() : string | ALL | Return name | |
getType() : string | ALL | Return type of current worker | |
getNodes() : array | PARENT | Return all nodes | |
getLimit() : number | ALL | Return the limit of workers allowed in current workers | |
getWorkers() : number | ALL | Return the number of workers | |
getWaitingWorkers() : number | ALL | Return the number of waiting workers | |
getRunningWorkers() : number | ALL | Return the number of running workers | |
getTotalWorkers() : number | ALL | Return the total number of workers (nodes included) | |
getTotalWaitingWorkers() : number | ALL | Return the total number of workers (nodes included) | |
getTotalRunningWorkers() : number | ALL | Return the total number of workers (nodes included) |
FAQs
Execute and manage your code asynchronously with workers and promise.
The npm package baby-workers receives a total of 2 weekly downloads. As such, baby-workers popularity was classified as not popular.
We found that baby-workers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.