summaryrefslogtreecommitdiffstats
path: root/lib/utils
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-06-11 12:38:19 +0200
committerSamy Pesse <samypesse@gmail.com>2016-06-11 12:38:19 +0200
commitaca4313fc3119c00cfdc9a3fa78e2164660f0918 (patch)
treef452feee08ffb15a7739321ea760920cac0cd58b /lib/utils
parent4cb5bb06fbdb823e740ba48536f43ba9cef18c07 (diff)
downloadgitbook-aca4313fc3119c00cfdc9a3fa78e2164660f0918.zip
gitbook-aca4313fc3119c00cfdc9a3fa78e2164660f0918.tar.gz
gitbook-aca4313fc3119c00cfdc9a3fa78e2164660f0918.tar.bz2
Enable long stack support when process.env.CI is true
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/promise.js87
1 files changed, 44 insertions, 43 deletions
diff --git a/lib/utils/promise.js b/lib/utils/promise.js
index 138546b..b5cca4b 100644
--- a/lib/utils/promise.js
+++ b/lib/utils/promise.js
@@ -2,34 +2,35 @@ var Q = require('q');
var Immutable = require('immutable');
// Debugging for long stack traces
-if (global.__DEV__ || process.env.DEBUG) {
+if (process.env.DEBUG || process.env.CI) {
Q.longStackSupport = true;
}
/**
- Reduce an array to a promise
-
- @param {Array|List} arr
- @param {Function(value, element, index)}
- @return {Promise<Mixed>}
-*/
+ * Reduce an array to a promise
+ *
+ * @param {Array|List} arr
+ * @param {Function(value, element, index)}
+ * @return {Promise<Mixed>}
+ */
function reduce(arr, iter, base) {
arr = Immutable.Iterable.isIterable(arr)? arr : Immutable.List(arr);
return arr.reduce(function(prev, elem, key) {
- return prev.then(function(val) {
+ return prev
+ .then(function(val) {
return iter(val, elem, key);
});
}, Q(base));
}
/**
- Iterate over an array using an async iter
-
- @param {Array|List} arr
- @param {Function(value, element, index)}
- @return {Promise}
-*/
+ * Iterate over an array using an async iter
+ *
+ * @param {Array|List} arr
+ * @param {Function(value, element, index)}
+ * @return {Promise}
+ */
function forEach(arr, iter) {
return reduce(arr, function(val, el, key) {
return iter(el, key);
@@ -37,12 +38,12 @@ function forEach(arr, iter) {
}
/**
- Transform an array
-
- @param {Array|List} arr
- @param {Function(value, element, index)}
- @return {Promise}
-*/
+ * Transform an array
+ *
+ * @param {Array|List} arr
+ * @param {Function(value, element, index)}
+ * @return {Promise}
+ */
function serie(arr, iter, base) {
return reduce(arr, function(before, item, key) {
return Q(iter(item, key))
@@ -54,12 +55,12 @@ function serie(arr, iter, base) {
}
/**
- Iter over an array and return first result (not null)
-
- @param {Array|List} arr
- @param {Function(element, index)}
- @return {Promise<Mixed>}
-*/
+ * Iter over an array and return first result (not null)
+ *
+ * @param {Array|List} arr
+ * @param {Function(element, index)}
+ * @return {Promise<Mixed>}
+ */
function some(arr, iter) {
arr = Immutable.List(arr);
@@ -73,12 +74,12 @@ function some(arr, iter) {
}
/**
- Map an array using an async (promised) iterator
-
- @param {Array|List} arr
- @param {Function(element, index)}
- @return {Promise<List>}
-*/
+ * Map an array using an async (promised) iterator
+ *
+ * @param {Array|List} arr
+ * @param {Function(element, index)}
+ * @return {Promise<List>}
+ */
function mapAsList(arr, iter) {
return reduce(arr, function(prev, entry, i) {
return Q(iter(entry, i))
@@ -90,12 +91,12 @@ function mapAsList(arr, iter) {
}
/**
- Map an array or map
-
- @param {Array|List|Map|OrderedMap} arr
- @param {Function(element, key)}
- @return {Promise<List|Map|OrderedMap>}
-*/
+ * Map an array or map
+ *
+ * @param {Array|List|Map|OrderedMap} arr
+ * @param {Function(element, key)}
+ * @return {Promise<List|Map|OrderedMap>}
+ */
function map(arr, iter) {
if (Immutable.Map.isMap(arr)) {
var type = 'Map';
@@ -122,11 +123,11 @@ function map(arr, iter) {
/**
- Wrap a function in a promise
-
- @param {Function} func
- @return {Funciton}
-*/
+ * Wrap a function in a promise
+ *
+ * @param {Function} func
+ * @return {Funciton}
+ */
function wrap(func) {
return function() {
var args = Array.prototype.slice.call(arguments, 0);