New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

yaku

Package Overview
Dependencies
Maintainers
1
Versions
137
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaku - npm Package Compare versions

Comparing version 0.7.12 to 0.8.0

lib/any.js

7

lib/_.js

@@ -5,2 +5,9 @@ var Promise = require("./yaku");

extendPrototype: function (src, target) {
for (var k in target) {
src.prototype[k] = target[k];
}
return src;
},
isArray: function (obj) {

@@ -7,0 +14,0 @@ return obj instanceof Array;

65

lib/async.js

@@ -1,11 +0,9 @@

var end = require("./end");
var _ = require("./_");
var genIterator = require("./genIterator");
var isPromise = require("./isPromise");
module.exports = function (limit, list, saveResults, progress) {
var isIterDone, iter, iterIndex, resutls, running;
var resutls, running;
resutls = [];
running = 0;
isIterDone = false;
iterIndex = 0;
if (!_.isNumber(limit)) {

@@ -20,27 +18,13 @@ progress = saveResults;

}
if (_.isArray(list)) {
iter = function () {
var el;
el = list[iterIndex];
if (el === void 0) {
return end;
} else if (_.isFunction(el)) {
return el();
} else {
return el;
}
};
} else if (_.isFunction(list)) {
iter = list;
} else {
throw new TypeError("wrong argument type: " + list);
}
var iter = genIterator(list);
return new _.Promise(function (resolve, reject) {
var addTask, allDone, i, results;
addTask = function () {
var index, p, task;
task = iter();
index = iterIndex++;
if (isIterDone || task === end) {
isIterDone = true;
var results, resultIndex = 0;
function addTask (index) {
var p, task;
task = iter.next();
if (task.done) {
if (running === 0) {

@@ -51,8 +35,11 @@ allDone();

}
if (isPromise(task)) {
p = task;
if (isPromise(task.value)) {
p = task.value;
} else {
p = _.Promise.resolve(task);
p = _.Promise.resolve(task.value);
}
running++;
p.then(function (ret) {

@@ -66,3 +53,3 @@ running--;

}
return addTask();
return addTask(resultIndex++);
})["catch"](function (err) {

@@ -72,5 +59,7 @@ running--;

});
return true;
};
allDone = function () {
}
function allDone () {
if (saveResults) {

@@ -81,7 +70,8 @@ return resolve(resutls);

}
};
i = limit;
}
var i = limit;
results = [];
while (i--) {
if (!addTask()) {
if (!addTask(resultIndex++)) {
break;

@@ -92,4 +82,5 @@ } else {

}
return results;
});
};
var _ = require("./_");
var end = require("./end");
var genIterator = require("./genIterator");
var isPromise = require("./isPromise");
module.exports = function () {
var fns;
fns = 1 <= arguments.length ? _.slice.call(arguments, 0) : [];
module.exports = function (iterable) {
var iter = genIterator(iterable);
return function (val) {
var genIter, iter, run;
genIter = function (arr) {
var iterIndex;
iterIndex = 0;
return function (val) {
var fn;
fn = arr[iterIndex++];
if (fn === void 0) {
return end;
} else if (_.isFunction(fn)) {
return fn(val);
} else {
return fn;
}
};
};
if (_.isArray(fns[0])) {
iter = genIter(fns[0]);
} else if (fns.length === 1 && _.isFunction(fns[0])) {
iter = fns[0];
} else if (fns.length > 1) {
iter = genIter(fns);
} else {
throw new TypeError("wrong argument type: " + fns);
}
run = function (preFn) {
return preFn.then(function (val) {
var fn;
fn = iter(val);
if (fn === end) {
function run (pre) {
return pre.then(function (val) {
var task = iter.next(val);
if (task.done) {
return val;
}
return run(isPromise(fn) ? fn : _.isFunction(fn) ? _.Promise.resolve(fn(val)) : _.Promise.resolve(fn));
var curr = task.value;
return run(
isPromise(curr) ? curr :
_.isFunction(curr) ? _.Promise.resolve(curr(val)) :
_.Promise.resolve(curr)
);
});
};
}
return run(_.Promise.resolve(val));
};
};

@@ -6,2 +6,21 @@ // This file contains all the non-ES6-standard helpers based on promise.

/**
* Similar with the `Promise.race`, but only rejects when every entry rejects.
* @param {iterable} iterable An iterable object, such as an Array.
* @return {Yaku}
* @example
* ```js
* var any = require('yaku/lib/any');
* any([
* 123,
* Promise.resolve(0),
* Promise.reject(1)
* ])
* .then((value) => {
* console.log(value); // => 123
* });
* ```
*/
any: require("./any"),
/**
* A function that helps run functions under a concurrent limitation.

@@ -11,8 +30,4 @@ * To run functions sequentially, use `yaku/lib/flow`.

* Default is `Infinity`.
* @param {Array | Function} list
* If the list is an array, it should be a list of functions or promises,
* and each function will return a promise.
* If the list is a function, it should be a iterator that returns
* a promise, when it returns `yaku/lib/end`, the iteration ends. Of course
* it can never end.
* @param {Iterable} list Any [iterable](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) object. It should be a lazy iteralbe object,
* don't pass in a normal Array with promises.
* @param {Boolean} saveResults Whether to save each promise's result or

@@ -27,3 +42,2 @@ * not. Default is true.

* var async = require('yaku/lib/async');
* var end = require('yaku/lib/end');
*

@@ -36,8 +50,9 @@ * var urls = [

* ];
* var tasks = [
* () => kit.request(url[0]),
* () => kit.request(url[1]),
* () => kit.request(url[2]),
* () => kit.request(url[3])
* ];
* var tasks = function * () {
* var i = 0;
* yield kit.request(url[i++]);
* yield kit.request(url[i++]);
* yield kit.request(url[i++]);
* yield kit.request(url[i++]);
* }();
*

@@ -48,9 +63,9 @@ * async(tasks).then(() => kit.log('all done!'));

*
* async(3, () => {
* async(3, { next: () => {
* var url = urls.pop();
* if (url)
* return kit.request(url);
* else
* return end;
* })
* return {
* done: !url,
* value: url && kit.request(url)
* };
* } })
* .then(() => kit.log('all done!'));

@@ -77,16 +92,6 @@ * ```

/**
* The end symbol.
* @return {Promise} A promise that will end the current pipeline.
*/
end: require("./end"),
/**
* Creates a function that is the composition of the provided functions.
* Besides, it can also accept async function that returns promise.
* See `yaku/lib/async`, if you need concurrent support.
* @param {Function | Array} fns Functions that return
* promise or any value.
* And the array can also contains promises or values other than function.
* If there's only one argument and it's a function, it will be treated as an iterator,
* when it returns `yaku/lib/end`, the iteration ends.
* @param {Iterable} list Any [iterable](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) object. It should be a lazy iteralbe object,
* don't pass in a normal Array with promises.
* @return {Function} `(val) -> Promise` A function that will return a promise.

@@ -126,14 +131,13 @@ * @example

* var flow = require('yaku/lib/flow');
* var end = require('yaku/lib/end');
*
* var list = [];
* function iter (url) {
* if (!url) return end;
*
* return kit.request(url)
* .then((body) => {
* list.push(body);
* var m = body.match(/href="(.+?)"/);
* if (m) return m[0];
* });
* return {
* done: !url,
* value: url && kit.request(url).then((body) => {
* list.push(body);
* var m = body.match(/href="(.+?)"/);
* if (m) return m[0];
* });
* };
* }

@@ -148,7 +152,2 @@ *

/**
* A function to make Yaku emit global rejection events.
*/
globalizeUnhandledRejection: require("./globalizeUnhandledRejection"),
/**
* **deprecate** Check if an object is a promise-like object.

@@ -162,2 +161,8 @@ * Don't use it to coercive a value to Promise, instead use `Promise.resolve`.

/**
* Create a symbole that never ends.
* @return {Promise} A promise that will end the current pipeline.
*/
never: require("./never"),
/**
* Convert a node callback style function to a function that returns

@@ -164,0 +169,0 @@ * promise when the last callback is not supplied.

/*
Yaku v0.7.12
Yaku v0.8.0
(c) 2015 Yad Smood. http://ysmood.org

@@ -268,2 +268,4 @@ License MIT

if (!countDown) settlePromise(p1, $resolved, []);
return p1;

@@ -286,29 +288,2 @@ };

/**
* Catch all possibly unhandled rejections. If you want to use specific
* format to display the error stack, overwrite it.
* If it is set, auto `console.error` unhandled rejection will be disabled.
* @param {Any} reason The rejection reason.
* @param {Yaku} p The promise that was rejected.
* @example
* ```js
* var Promise = require('yaku');
* Promise.onUnhandledRejection = (reason) => {
* console.error(reason);
* };
*
* // The console will log an unhandled rejection error message.
* Promise.reject('my reason');
*
* // The below won't log the unhandled rejection error message.
* Promise.reject('v').catch(() => {});
* ```
*/
Yaku.onUnhandledRejection = function (reason, p) {
if (root.console) {
var info = genStackInfo(reason, p);
console.error("Unhandled Rejection:", info[0], info[1] || "");
}
};
/**
* It is used to enable the long stack trace.

@@ -352,2 +327,3 @@ * Once it is enabled, it can't be reverted.

Yaku.stack = genStackInfo;

@@ -372,2 +348,3 @@ // ********************** Private **********************

}
return src;
}

@@ -449,11 +426,9 @@

function ArrIter (arr) {
this.arr = arr;
this.len = arr.length;
}
// Hack: we don't create new object to pass the newly iterated object.
var $ArrIterContainer = {};
extendPrototype(ArrIter, {
var ArrIter = extendPrototype(function (arr) {
this.arr = arr;
this.len = arr.length;
}, {
i: 0,

@@ -483,2 +458,6 @@ next: function () {

}
if (isFunction(obj.next)) {
return obj;
}
}

@@ -540,4 +519,18 @@ throw genTypeError("invalid_argument");

var scheduleUnhandledRejection = genScheduler(9, function (p) {
if (!hashOnRejected(p))
Yaku.onUnhandledRejection(p._value, p);
if (!hashOnRejected(p)) {
var process = root.process
, onunhandledrejection = root.onunhandledrejection
, console = root.console
, reason = p._value
, eventName = "unhandledRejection";
if (process && process.listeners(eventName).length) {
process.emit(eventName, reason, p);
} else if (onunhandledrejection) {
onunhandledrejection({ promise: p, reason: reason });
} else if (console) {
var info = genStackInfo(reason, p);
console.error(eventName + ":", info[0], info[1] || "");
}
}
});

@@ -544,0 +537,0 @@

@@ -1,1 +0,1 @@

!function(){"use strict";function n(n,t){for(var e in t)n.prototype[e]=t[e]}function t(n){return"object"==typeof n}function e(n){return"function"==typeof n}function r(){try{return U.apply(A,arguments)}catch(n){return Y.e=n,Y}}function u(n,t){return U=n,A=t,r}function o(n,t){function e(){for(var e=0;u>e;)t(r[e],r[e+1]),r[e++]=j,r[e++]=j;u=0,r.length>n&&(r.length=n)}var r=Array(n),u=0;return function(n,t){r[u++]=n,r[u++]=t,2===u&&F.nextTick(e)}}function i(n){this.arr=n,this.len=n.length}function c(n){if(n){var t=n[F.Symbol.iterator];if(e(t))return t.call(n);if(n instanceof Array)return new i(n)}throw a("invalid_argument")}function a(n){return new TypeError(n)}function f(n){return((new Error).stack||"").replace("Error",n?"":E)}function l(n){return n&&n._Yaku}function s(){return new F(L)}function _(n,t){return function(e){b&&(n[S]=f(!0)),t===R?m(n,e):k(n,t,e)}}function v(n,t,r,u){return e(r)&&(t._onFulfilled=r),e(u)&&(t._onRejected=u),b&&(t._pre=n),n[n._pCount++]=t,n._state!==T&&$(n,t),t}function p(n){if(n._umark)return!0;n._umark=!0;for(var t,e=0,r=n._pCount;r>e;)if(t=n[e++],t._onRejected||p(t))return!0}function d(n,t){function e(n){return n.replace(/^\s+|\s+$/g,"")}function r(n){return c.push(e(n))}function u(n,t){return t&&(i=n.indexOf("\n"+E))>0&&(n=n.slice(0,i)),n.replace(/^.+\/node_modules\/yaku\/.+\n?/gm,"")}var o,i,c=[];return b&&t[C]&&(t[S]&&r(t[S]),function a(n){n&&(a(n._next),r(n[C]),a(n._pre))}(t)),o="\n"+c.join("\n"),[n&&n.stack?u(e(n.stack),!0):n,u(o)]}function h(n,t){return n(t)}function k(n,t,e){var r,u,o=0,i=n._pCount;if(n._state===T)for(n._state=t,n._value=e,t===w&&(b&&e&&e.stack&&(u=d(e,n),e.stack=u[0]+u[1]),q(n));i>o;)r=n[o++],r._state===T&&$(n,r);return n}function m(n,r){if(r===n&&r)return k(n,w,a("promise_circular_chain")),n;if(null!=r&&(e(r)||t(r))){var o=u(y)(r);if(o===Y)return k(n,w,o.e),n;e(o)?(b&&l(r)&&(n._next=r),g(n,r,o)):k(n,R,r)}else k(n,R,r);return n}function y(n){return n.then}function g(n,t,e){var r=u(e,t)(function(e){t&&(t=null,m(n,e))},function(e){t&&(t=null,k(n,w,e))});r===Y&&t&&(k(n,w,r.e),t=null)}var j,x="object"==typeof global?global:window,b=!1,w=0,R=1,T=2,C="_pt",S="_st",E="From previous event:",F=module.exports=function(n){var t,e=this;b&&(e[C]=f()),n!==L&&(t=u(n,e)(_(e,R),_(e,w)),t===Y&&k(e,w,t.e))};n(F,{then:function(n,t){return v(this,s(),n,t)},"catch":function(n){return this.then(j,n)},_state:T,_pCount:0,_pre:null,_Yaku:1}),F.resolve=function(n){return l(n)?n:m(s(),n)},F.reject=function(n){return k(s(),w,n)},F.race=function(n){for(var t,e=c(n),r=s();!(t=e.next()).done&&(m(r,t.value),r._state===T););return r},F.all=function(n){for(var t,e=c(n),r=F.resolve,u=s(),o=[],i=0,a=function(n){k(u,w,n)},f=function(n,t){r(t).then(function(t){o[n]=t,--i||k(u,R,o)},a)};!(t=e.next()).done;)f(i++,t.value);return u},F.Symbol=x.Symbol||{},F.onUnhandledRejection=function(n,t){if(x.console){var e=d(n,t);console.error("Unhandled Rejection:",e[0],e[1]||"")}},F.enableLongStackTrace=function(){b=!0},F.nextTick=x.process?x.process.nextTick:function(n){setTimeout(n)};var U,A,Y={e:null},L={},O={};n(i,{i:0,next:function(){var n=this;return O.value=n.arr[n.i++],O.done=n.i>n.len,O}});var $=o(999,function(n,t){var e,r;return r=n._state?t._onFulfilled:t._onRejected,r===j?void k(t,n._state,n._value):(e=u(h)(r,n._value),e===Y?void k(t,w,e.e):void m(t,e))}),q=o(9,function(n){p(n)||F.onUnhandledRejection(n._value,n)})}();
!function(){"use strict";function n(n,t){for(var e in t)n.prototype[e]=t[e];return n}function t(n){return"object"==typeof n}function e(n){return"function"==typeof n}function r(){try{return F.apply(A,arguments)}catch(n){return Y.e=n,Y}}function u(n,t){return F=n,A=t,r}function o(n,t){function e(){for(var e=0;u>e;)t(r[e],r[e+1]),r[e++]=g,r[e++]=g;u=0,r.length>n&&(r.length=n)}var r=Array(n),u=0;return function(n,t){r[u++]=n,r[u++]=t,2===u&&E.nextTick(e)}}function i(n){if(n){var t=n[E.Symbol.iterator];if(e(t))return t.call(n);if(n instanceof Array)return new $(n);if(e(n.next))return n}throw c("invalid_argument")}function c(n){return new TypeError(n)}function f(n){return((new Error).stack||"").replace("Error",n?"":S)}function a(n){return n&&n._Yaku}function l(){return new E(L)}function s(n,t){return function(e){j&&(n[R]=f(!0)),t===w?k(n,e):h(n,t,e)}}function _(n,t,r,u){return e(r)&&(t._onFulfilled=r),e(u)&&(t._onRejected=u),j&&(t._pre=n),n[n._pCount++]=t,n._state!==T&&q(n,t),t}function v(n){if(n._umark)return!0;n._umark=!0;for(var t,e=0,r=n._pCount;r>e;)if(t=n[e++],t._onRejected||v(t))return!0}function p(n,t){function e(n){return n.replace(/^\s+|\s+$/g,"")}function r(n){return c.push(e(n))}function u(n,t){return t&&(i=n.indexOf("\n"+S))>0&&(n=n.slice(0,i)),n.replace(/^.+\/node_modules\/yaku\/.+\n?/gm,"")}var o,i,c=[];return j&&t[C]&&(t[R]&&r(t[R]),function f(n){n&&(f(n._next),r(n[C]),f(n._pre))}(t)),o="\n"+c.join("\n"),[n&&n.stack?u(e(n.stack),!0):n,u(o)]}function d(n,t){return n(t)}function h(n,t,e){var r,u,o=0,i=n._pCount;if(n._state===T)for(n._state=t,n._value=e,t===b&&(j&&e&&e.stack&&(u=p(e,n),e.stack=u[0]+u[1]),z(n));i>o;)r=n[o++],r._state===T&&q(n,r);return n}function k(n,r){if(r===n&&r)return h(n,b,c("promise_circular_chain")),n;if(null!=r&&(e(r)||t(r))){var o=u(m)(r);if(o===Y)return h(n,b,o.e),n;e(o)?(j&&a(r)&&(n._next=r),y(n,r,o)):h(n,w,r)}else h(n,w,r);return n}function m(n){return n.then}function y(n,t,e){var r=u(e,t)(function(e){t&&(t=null,k(n,e))},function(e){t&&(t=null,h(n,b,e))});r===Y&&t&&(h(n,b,r.e),t=null)}var g,x="object"==typeof global?global:window,j=!1,b=0,w=1,T=2,C="_pt",R="_st",S="From previous event:",E=module.exports=function(n){var t,e=this;j&&(e[C]=f()),n!==L&&(t=u(n,e)(s(e,w),s(e,b)),t===Y&&h(e,b,t.e))};n(E,{then:function(n,t){return _(this,l(),n,t)},"catch":function(n){return this.then(g,n)},_state:T,_pCount:0,_pre:null,_Yaku:1}),E.resolve=function(n){return a(n)?n:k(l(),n)},E.reject=function(n){return h(l(),b,n)},E.race=function(n){for(var t,e=i(n),r=l();!(t=e.next()).done&&(k(r,t.value),r._state===T););return r},E.all=function(n){for(var t,e=i(n),r=E.resolve,u=l(),o=[],c=0,f=function(n){h(u,b,n)},a=function(n,t){r(t).then(function(t){o[n]=t,--c||h(u,w,o)},f)};!(t=e.next()).done;)a(c++,t.value);return c||h(u,w,[]),u},E.Symbol=x.Symbol||{},E.enableLongStackTrace=function(){j=!0},E.nextTick=x.process?x.process.nextTick:function(n){setTimeout(n)},E.stack=p;var F,A,Y={e:null},L={},O={},$=n(function(n){this.arr=n,this.len=n.length},{i:0,next:function(){var n=this;return O.value=n.arr[n.i++],O.done=n.i>n.len,O}}),q=o(999,function(n,t){var e,r;return r=n._state?t._onFulfilled:t._onRejected,r===g?void h(t,n._state,n._value):(e=u(d)(r,n._value),e===Y?void h(t,b,e.e):void k(t,e))}),z=o(9,function(n){if(!v(n)){var t=x.process,e=x.onunhandledrejection,r=x.console,u=n._value,o="unhandledRejection";if(t&&t.listeners(o).length)t.emit(o,u,n);else if(e)e({promise:n,reason:u});else if(r){var i=p(u,n);r.error(o+":",i[0],i[1]||"")}}})}();
{
"name": "yaku",
"version": "0.7.12",
"version": "0.8.0",
"description": "A light-weight ES6 Promises/A+ implementation that doesn't hurt.",

@@ -43,2 +43,3 @@ "main": "lib/yaku.js",

"eslint": "1.5.1",
"junit": "0.6.1",
"nokit": "0.14.7",

@@ -69,3 +70,6 @@ "promises-aplus-tests": "*",

],
"quotes": [2, "double"],
"quotes": [
2,
"double"
],
"no-cond-assign": 0,

@@ -72,0 +76,0 @@ "no-trailing-spaces": 2,

@@ -22,3 +22,3 @@ <a href="http://promisesaplus.com/">

- The minified file is only 3.3KB (1.5KB gzipped) ([Bluebird][] / 73KB, [ES6-promise][] / 18KB)
- The minified file is only 3.4KB (1.5KB gzipped) ([Bluebird][] / 73KB, [ES6-promise][] / 18KB)
- [Better "possibly unhandled rejection" and "long stack trace"][docs/debugHelperComparison.md] than [Bluebird][]

@@ -75,3 +75,3 @@ - Much better performance than the native Promise

| -------------------- | -------------------- | --------------- | ------- | --------- |
| Yaku | 257ms / 110MB | 126ms / 80MB | +++ | 3.3KB |
| Yaku | 257ms / 110MB | 126ms / 80MB | +++ | 3.4KB |
| [Bluebird][] v2.9 | 249ms / 102MB | 155ms / 80MB | +++++++ | 73KB |

@@ -114,9 +114,14 @@ | [ES6-promise][] v2.3 | 427ms / 120MB | 92ms / 78MB | + | 18KB |

- Why not the use the `window` or `process` to emit the `unhandledRejection`?
> Yaku will not touch any global API, instead I will leave enought APIs to let user achieve it easily.
> For example, you can use `utils.globalizeUnhandledRejection()` to do it.
# Unhandled Rejection
Yaku will report any unhandled rejection via `console.error` by default, in case you forget to write `catch`.
You can catch with them manually:
- Browser: `window.onunhandledrejection = ({ promise, reason }) => { /* Your Code */ };`
- Node: `process.on("unhandledRejection", (reason, promise) => { /* Your Code */ });`
For more spec read [Unhandled Rejection Tracking Browser Events](https://github.com/domenic/unhandled-rejections-browser-spec).
# API

@@ -349,3 +354,3 @@

- ### **[Yaku.Symbol](src/yaku.js?source#L277)**
- ### **[Yaku.Symbol](src/yaku.js?source#L279)**

@@ -365,33 +370,4 @@ The ES6 Symbol object that Yaku should use, by default it will use the

- ### **[Yaku.onUnhandledRejection(reason, p)](src/yaku.js?source#L299)**
- ### **[Yaku.enableLongStackTrace](src/yaku.js?source#L293)**
Catch all possibly unhandled rejections. If you want to use specific
format to display the error stack, overwrite it.
If it is set, auto `console.error` unhandled rejection will be disabled.
- **<u>param</u>**: `reason` { _Any_ }
The rejection reason.
- **<u>param</u>**: `p` { _Yaku_ }
The promise that was rejected.
- **<u>example</u>**:
```js
var Promise = require('yaku');
Promise.onUnhandledRejection = (reason) => {
console.error(reason);
};
// The console will log an unhandled rejection error message.
Promise.reject('my reason');
// The below won't log the unhandled rejection error message.
Promise.reject('v').catch(() => {});
```
- ### **[Yaku.enableLongStackTrace](src/yaku.js?source#L318)**
It is used to enable the long stack trace.

@@ -410,3 +386,3 @@ Once it is enabled, it can't be reverted.

- ### **[Yaku.nextTick](src/yaku.js?source#L341)**
- ### **[Yaku.nextTick](src/yaku.js?source#L316)**

@@ -436,3 +412,3 @@ Only Node has `process.nextTick` function. For browser there are

- ### **[genIterator(obj)](src/yaku.js?source#L463)**
- ### **[genIterator(obj)](src/yaku.js?source#L438)**

@@ -461,4 +437,28 @@ Generate a iterator

- ### **[async(limit, list, saveResults, progress)](src/utils.js?source#L54)**
- ### **[any(iterable)](src/utils.js?source#L22)**
Similar with the `Promise.race`, but only rejects when every entry rejects.
- **<u>param</u>**: `iterable` { _iterable_ }
An iterable object, such as an Array.
- **<u>return</u>**: { _Yaku_ }
- **<u>example</u>**:
```js
var any = require('yaku/lib/any');
any([
123,
Promise.resolve(0),
Promise.reject(1)
])
.then((value) => {
console.log(value); // => 123
});
```
- ### **[async(limit, list, saveResults, progress)](src/utils.js?source#L69)**
A function that helps run functions under a concurrent limitation.

@@ -472,9 +472,6 @@ To run functions sequentially, use `yaku/lib/flow`.

- **<u>param</u>**: `list` { _Array | Function_ }
- **<u>param</u>**: `list` { _Iterable_ }
If the list is an array, it should be a list of functions or promises,
and each function will return a promise.
If the list is a function, it should be a iterator that returns
a promise, when it returns `yaku/lib/end`, the iteration ends. Of course
it can never end.
Any [iterable](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) object. It should be a lazy iteralbe object,
don't pass in a normal Array with promises.

@@ -498,3 +495,2 @@ - **<u>param</u>**: `saveResults` { _Boolean_ }

var async = require('yaku/lib/async');
var end = require('yaku/lib/end');

@@ -507,8 +503,9 @@ var urls = [

];
var tasks = [
() => kit.request(url[0]),
() => kit.request(url[1]),
() => kit.request(url[2]),
() => kit.request(url[3])
];
var tasks = function * () {
var i = 0;
yield kit.request(url[i++]);
yield kit.request(url[i++]);
yield kit.request(url[i++]);
yield kit.request(url[i++]);
}();

@@ -519,13 +516,13 @@ async(tasks).then(() => kit.log('all done!'));

async(3, () => {
async(3, { next: () => {
var url = urls.pop();
if (url)
return kit.request(url);
else
return end;
})
return {
done: !url,
value: url && kit.request(url)
};
} })
.then(() => kit.log('all done!'));
```
- ### **[callbackify(fn, self)](src/utils.js?source#L63)**
- ### **[callbackify(fn, self)](src/utils.js?source#L78)**

@@ -543,3 +540,3 @@ If a function returns promise, convert it to

- ### **[Deferred](src/utils.js?source#L69)**
- ### **[Deferred](src/utils.js?source#L84)**

@@ -549,23 +546,11 @@ **deprecate** Create a `jQuery.Deferred` like object.

- ### **[end()](src/utils.js?source#L75)**
- ### **[flow(list)](src/utils.js?source#L142)**
The end symbol.
- **<u>return</u>**: { _Promise_ }
A promise that will end the current pipeline.
- ### **[flow(fns)](src/utils.js?source#L138)**
Creates a function that is the composition of the provided functions.
Besides, it can also accept async function that returns promise.
See `yaku/lib/async`, if you need concurrent support.
- **<u>param</u>**: `fns` { _Function | Array_ }
- **<u>param</u>**: `list` { _Iterable_ }
Functions that return
promise or any value.
And the array can also contains promises or values other than function.
If there's only one argument and it's a function, it will be treated as an iterator,
when it returns `yaku/lib/end`, the iteration ends.
Any [iterable](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Iteration_protocols) object. It should be a lazy iteralbe object,
don't pass in a normal Array with promises.

@@ -612,14 +597,13 @@ - **<u>return</u>**: { _Function_ }

var flow = require('yaku/lib/flow');
var end = require('yaku/lib/end');
var list = [];
function iter (url) {
if (!url) return end;
return kit.request(url)
.then((body) => {
list.push(body);
var m = body.match(/href="(.+?)"/);
if (m) return m[0];
});
return {
done: !url,
value: url && kit.request(url).then((body) => {
list.push(body);
var m = body.match(/href="(.+?)"/);
if (m) return m[0];
});
};
}

@@ -631,8 +615,4 @@

- ### **[globalizeUnhandledRejection](src/utils.js?source#L143)**
- ### **[isPromise(obj)](src/utils.js?source#L150)**
A function to make Yaku emit global rejection events.
- ### **[isPromise(obj)](src/utils.js?source#L151)**
**deprecate** Check if an object is a promise-like object.

@@ -645,4 +625,12 @@ Don't use it to coercive a value to Promise, instead use `Promise.resolve`.

- ### **[promisify(fn, self)](src/utils.js?source#L180)**
- ### **[never()](src/utils.js?source#L156)**
Create a symbole that never ends.
- **<u>return</u>**: { _Promise_ }
A promise that will end the current pipeline.
- ### **[promisify(fn, self)](src/utils.js?source#L185)**
Convert a node callback style function to a function that returns

@@ -681,3 +669,3 @@ promise when the last callback is not supplied.

- ### **[sleep(time, val)](src/utils.js?source#L193)**
- ### **[sleep(time, val)](src/utils.js?source#L198)**

@@ -703,3 +691,3 @@ Create a promise that will wait for a while before resolution.

- ### **[source(executor)](src/utils.js?source#L274)**
- ### **[source(executor)](src/utils.js?source#L279)**

@@ -799,3 +787,3 @@ Create a composable event source function.

- ### **[retry(countdown, fn, this)](src/utils.js?source#L323)**
- ### **[retry(countdown, fn, this)](src/utils.js?source#L328)**

@@ -867,3 +855,3 @@ Retry a function until it resolves before a mount of times, or reject with all

- ### **[throw(err)](src/utils.js?source#L337)**
- ### **[throw(err)](src/utils.js?source#L342)**

@@ -870,0 +858,0 @@ Throw an error to break the program.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc