summaryrefslogtreecommitdiff
path: root/support/es.test.js
blob: 3dbb7d68cdcee17cad1a02c6136f71dbdac45f66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// simple async example to test ES module build output

import {waterfall as waterfall} from  "../build-es/index";
import {wrapSync} from  "../build-es/index";
import async from "../build-es/index";
import constant from "../build-es/constant";
import forEachOf from "../build-es/forEachOf";

waterfall([
    constant(42),
    function (val, next) {
        async.setImmediate(function () {
            next(null, val);
        });
    },
    wrapSync(function (a) { return a; }),
    function (val, next) {
        async.forEachOf({a: 1}, function (val, key, cb) {
            if (val !== 1 && key !== 'a') return cb(new Error('fail!'));
            cb();
        }, function (err) { next (err, val)});
    },
    function (val, next) {
        forEachOf([1, 2, 3], function (v, key, cb) {
            val += key
            cb()
        }, function (err) { next(err, val - 3) })
    }
], function (err, result) {
    if (err) { throw err; }
    console.log(result);
    if (result !== 42) {
        console.log("fail");
        process.exit(1);
    }
});