10 examples of 'node js async waterfall example' in JavaScript

Every line of 'node js 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
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};
50function webpackAsync(webpackConfig): Promise {
51 return new Promise((resolve, reject) => {
52 const compiler = webpack(webpackConfig)
53 compiler.run((err, stats) => {
54 const statsJson = stats.toJson()
55 const { errors, warnings } = statsJson
56
57 if (err) {
58 log('Webpack compiler encountered a fatal error.')
59 reject(new PluginError('webpack', err.toString()))
60 }
61 if (errors.length > 0) {
62 log('Webpack compiler encountered errors.')
63 reject(new PluginError('webpack', errors.toString()))
64 }
65 if (warnings.length > 0) {
66 log('Webpack compiler encountered warnings.')
67 reject(new PluginError('webpack', warnings.toString()))
68 }
69
70 resolve(statsJson)
71 })
72 })
73}
68export function isAsync(val) {
69 return val?.[Symbol.toStringTag] === 'AsyncFunction'
70}
149exports.async = function asyncFunction(iter) {
150 return new Promise((resolve, reject) => {
151 resume('next', undefined);
152 function resume(type, value) {
153 try {
154 let result = iter[type](value);
155 if (result.done) {
156 resolve(result.value);
157 } else {
158 Promise.resolve(result.value).then(
159 x => resume('next', x),
160 x => resume('throw', x));
161 }
162 } catch (x) {
163 reject(x);
164 }
165 }
166 });
167};
4export function wrapInAsyncFunction(code: string): string {
5 const codeInAsyncFunction = `(async () => {
6 ${code}
7 })()`;
8
9 const ast = recast.parse(codeInAsyncFunction, { parser: babylon });
10 const body = ast.program.body[0].expression.callee.body.body;
11
12 if (body.length !== 0) {
13 const last = body.pop();
14 if (last.type === "ExpressionStatement") {
15 body.push({
16 type: "ReturnStatement",
17 argument: last,
18 });
19 } else {
20 body.push(last);
21 }
22 }
23
24 // Remove var, let, const from variable declarations to make them available in context
25 // tslint:disable-next-line:no-object-mutation
26 ast.program.body[0].expression.callee.body.body = body.map((node: any) => {
27 if (node.type === "VariableDeclaration") {
28 return {
29 type: "ExpressionStatement",
30 expression: {
31 type: "SequenceExpression",
32 expressions: node.declarations.map((declaration: any) => ({
33 type: "AssignmentExpression",
34 operator: "=",
35 left: declaration.id,
36 right: declaration.init,
37 })),
38 },
39 };
40 } else {
41 return node;
42 }
43 });
44
45 return recast.print(ast).code;
46}
80runNode : function runNode(node) {
81 var dependencies = [].concat(node.dependencies);
82 var hasRejectedDependency = false;
83
84 var fulfilledDependencies = dependencies.filter(function (dependencyName) {
85 if (this.hasOwnProperty(dependencyName) === false) {
86 return;
87 }
88
89 if (this[dependencyName].isFulfilled === true || this[dependencyName].isRejected === true) {
90 if (this[dependencyName].isRejected === true) {
91 hasRejectedDependency = true;
92 }
93 return true;
94 }
95 }, this);
96
97 if (dependencies.length === fulfilledDependencies.length) {
98 var nodeLikeObject = {
99 success : function nodeSuccess(data) {
100 node.fulfill(data);
101 },
102 fail : function nodeFail(error) {
103 node.reject(error);
104 }
105 };
106
107 if (hasRejectedDependency === false) {
108 nodeLikeObject.data = {};
109 fulfilledDependencies.forEach(function fulfilledDependenciesIterator(dependencyName) {
110 nodeLikeObject.data[dependencyName] = this[dependencyName].data;
111 }, this);
112 }
113 else {
114 nodeLikeObject.errors = {};
115 fulfilledDependencies.forEach(function (dependencyName) {
116 nodeLikeObject.errors[dependencyName] = this[dependencyName].error;
117 }, this);
118 }
119
120 node.run(nodeLikeObject);
121 }
122},
11main$0.main = function main$1() {
12 return async.async(dart.dynamic, function* main() {
13 yield ui$.webOnlyInitializePlatform();
14 main$.main();
15 });
16};
155function isAsyncFunction (value /* :mixed */) /* :boolean */ {
156 return getObjectType(value) === '[object AsyncFunction]'
157}
588function asyncJS(js, fn) {
589 return new AsyncQueue(js, fn);
590}
143function onAfterAwait(node) {
144 insertText(node.range[1], node.range[1], ')');
145}

Related snippets