]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/async-some/some.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / async-some / some.js
1 var assert     = require("assert")
2 var dezalgoify = require("dezalgo")
3
4 module.exports = some
5
6 /**
7  * short-circuited async Array.prototype.some implementation
8  *
9  * Serially evaluates a list of values from a JS array or arraylike
10  * against an asynchronous predicate, terminating on the first truthy
11  * value. If the predicate encounters an error, pass it to the completion
12  * callback. Otherwise, pass the truthy value passed by the predicate, or
13  * `false` if no truthy value was passed.
14  */
15 function some (list, test, cb) {
16   assert("length" in list, "array must be arraylike")
17   assert.equal(typeof test, "function", "predicate must be callable")
18   assert.equal(typeof cb, "function", "callback must be callable")
19
20   var array   = slice(list)
21     , index   = 0
22     , length  = array.length
23     , hecomes = dezalgoify(cb)
24
25   map()
26
27   function map () {
28     if (index >= length) return hecomes(null, false)
29
30     test(array[index], reduce)
31   }
32
33   function reduce (er, result) {
34     if (er) return hecomes(er, false)
35     if (result) return hecomes(null, result)
36
37     index++
38     map()
39   }
40 }
41
42 // Array.prototype.slice on arguments arraylike is expensive
43 function slice(args) {
44   var l = args.length, a = [], i
45   for (i = 0; i < l; i++) a[i] = args[i]
46   return a
47 }