6.0.4 • Published 4 years ago
funccon v6.0.4
FuncCon
(function concurrence)
...which can also be used to make things run in sequnce, by setting the size aregument to 1
The "size" argument sets how many functions are allowed to run simultaniously
var con = require(funccon);
con({
size: 100, // number of function allowed to run simulataniously
funcs: [ // your functions
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 1 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete(1); // the complete function tells funccon to move on
// Whatever you pass it will be given to the done function as an argument
}
}, 500);
},
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 2 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete('foo');
}
}, 500);
},
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 3 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete({
shit: 'real'
}, 'asfdas');
}
}, 500);
},
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 4 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete('boom?');
}
}, 500);
}
],
done: function() { // this fires when all the above functions are complete
console.log('completeFunction called, done');
console.log();
con({
size: 1, // number of function allowed to run simulataniously
funcs: [ // your functions
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 1 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete(1); // the complete function tells funccon to move on
// Whatever you pass it will be given to the done function as an argument
}
}, 500);
},
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 2 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete('foo');
}
}, 500);
},
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 3 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete({
shit: 'real'
}, 'asfdas');
}
}, 500);
},
(complete) => {
var counter = 0;
var a = setInterval(function() {
counter++;
console.log('func 4 counter: ' + counter);
if (counter >= 4) {
clearInterval(a);
complete('boom?');
}
}, 500);
}
],
done: function() { // this fires when all the above functions are complete
console.log('completeFunction called, done');
}
});
}
});
6.0.4
4 years ago
6.0.3
4 years ago
6.0.2
4 years ago
6.0.1
4 years ago
6.0.0
4 years ago
5.1.3
5 years ago
5.1.2
5 years ago
5.0.2
5 years ago
5.0.1
6 years ago
5.0.0
6 years ago
3.0.2
7 years ago
3.0.1
7 years ago
3.0.0
7 years ago
2.0.1
7 years ago
2.0.0
7 years ago
1.0.3
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago