3 examples of 'node async waterfall example' in JavaScript

Every line of 'node async waterfall example' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
143function onAfterAwait(node) {
144 insertText(node.range[1], node.range[1], ')');
145}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

34return function asyncFunction() {
35 const args = Array.from(arguments);
36 return new Promise(function (resolve, reject) {
37 let gen;
38
39 function step(next) {
40 const value = next.value;
41 if (next.done) {
42 return resolve(value);
43 }
44 if (value instanceof Promise) {
45 return value.then(
46 result => step(gen.next(result)),
47 error => {
48 try {
49 step(gen.throw(error));
50 } catch (err) {
51 throw err;
52 }
53 }
54 ).catch((err) => {
55 warn("Unhandled error in async function.", err);
56 reject(err);
57 });
58 }
59 step(gen.next(value));
60 }
61
62 if (typeof func !== "function") {
63 reject(new TypeError("Expected a Function."));
64 }
65 // not a generator, wrap it.
66 if (func.constructor.name !== "GeneratorFunction") {
67 gen = (function*() {
68 return func.call(self, ...args);
69 }());
70 } else {
71 gen = func.call(self, ...args);
72 }
73 try {
74 step(gen.next());
75 } catch (err) {
76 warn("The generator threw immediately.", err);
77 reject(err);
78 }
79 });
80};
69runChildNode(node) {
70 this.currentNode = node;
71 this.currentNode.started = true;
72 Logger.log(`\n ${Logger.colors.green('→')} Running command: ${Logger.colors.light_green(node.fullName)} (${AsyncTree.printArguments(node)})`);
73
74 return node.run()
75 .then(result => {
76 let abortOnFailure = false;
77
78 if (result instanceof Error) {
79 node.reject(result);
80 abortOnFailure = result.abortOnFailure || Utils.isUndefined(result.abortOnFailure);
81 } else {
82 node.resolve(result);
83 }
84
85 Logger.log(` ${Logger.colors.green('→')} Completed command: ${Logger.colors.light_green(node.fullName)}` +
86 ` (${AsyncTree.printArguments(node)}) (${node.elapsedTime}ms)`);
87
88 if (abortOnFailure) {
89 return this.done(result);
90 }
91
92 return this.traverse();
93 });
94}

Related snippets