7 examples of 'async series node js' in JavaScript

Every line of 'async series node js' 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
588function asyncJS(js, fn) {
589 return new AsyncQueue(js, fn);
590}
191Tapable.prototype.applyPluginsAsyncSeries = Tapable.prototype.applyPluginsAsync = function applyPluginsAsyncSeries(name) {
192 var args = Array.prototype.slice.call(arguments, 1);
193 var callback = args.pop();
194 var plugins = this._plugins[name];
195 if(!plugins || plugins.length === 0) return callback();
196 var i = 0;
197 var _this = this;
198 args.push(copyProperties(callback, function next(err) {
199 if(err) return callback(err);
200 i++;
201 if(i >= plugins.length) {
202 return callback();
203 }
204 plugins[i].apply(_this, args);
205 }));
206 plugins[0].apply(this, args);
207};
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}
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};
68export function isAsync(val) {
69 return val?.[Symbol.toStringTag] === 'AsyncFunction'
70}
143function onAfterAwait(node) {
144 insertText(node.range[1], node.range[1], ')');
145}
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};

Related snippets