]> 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/README.md
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 / README.md
1 # some
2
3 Short-circuited async Array.prototype.some implementation.
4
5 Serially evaluates a list of values from a JS array or arraylike
6 against an asynchronous predicate, terminating on the first truthy
7 value. If the predicate encounters an error, pass it to the completion
8 callback. Otherwise, pass the truthy value passed by the predicate, or
9 `false` if no truthy value was passed.
10
11 Is
12 [Zalgo](http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony)-proof,
13 browser-safe, and pretty efficient.
14
15 ## Usage
16
17 ```javascript
18 var some = require("async-some");
19 var resolve = require("path").resolve;
20 var stat = require("fs").stat;
21 var readFileSync = require("fs").readFileSync;
22
23 some(["apple", "seaweed", "ham", "quince"], porkDetector, function (error, match) {
24   if (error) return console.error(error);
25
26   if (match) return console.dir(JSON.parse(readFileSync(match)));
27
28   console.error("time to buy more Sporkleā„¢!");
29 });
30
31 var PREFIX = resolve(__dirname, "../pork_store");
32 function porkDetector(value, cb) {
33   var path = resolve(PREFIX, value + ".json");
34   stat(path, function (er, stat) {
35     if (er) {
36       if (er.code === "ENOENT") return cb(null, false);
37
38       return cb(er);
39     }
40
41     cb(er, path);
42   });
43 }
44 ```
45
46 ### some(list, test, callback)
47
48 * `list` {Object} An arraylike (either an Array or the arguments arraylike) to
49   be checked.
50 * `test` {Function} The predicate against which the elements of `list` will be
51   tested. Takes two parameters:
52   * `element` {any} The element of the list to be tested.
53   * `callback` {Function} The continuation to be called once the test is
54     complete. Takes (again) two values:
55     * `error` {Error} Any errors that the predicate encountered.
56     * `value` {any} A truthy value. A non-falsy result terminates checking the
57       entire list.
58 * `callback` {Function} The callback to invoke when either a value has been
59   found or the entire input list has been processed with no result. Is invoked
60   with the traditional two parameters:
61   * `error` {Error} Errors that were encountered during the evaluation of some().
62   * `match` {any} Value successfully matched by `test`, if any.