當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Promise.all函數代碼示例

本文整理匯總了TypeScript中@dojo/shim/Promise.all函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript all函數的具體用法?TypeScript all怎麽用?TypeScript all使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了all函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

			request.on('end', () => {
				try {
					let rawMessages: any = JSON.parse(data);

					if (!Array.isArray(rawMessages)) {
						rawMessages = [rawMessages];
					}

					const messages: Message[] = rawMessages.map(function (messageString: string) {
						return JSON.parse(messageString);
					});

					Promise.all(messages.map(message => this._handleMessage(message))).then(
						() => {
							response.statusCode = 204;
							response.end();
						},
						() => {
							response.statusCode = 500;
							response.end();
						}
					);
				}
				catch (error) {
					response.statusCode = 500;
					response.end();
				}
			});
開發者ID:bryanforbes,項目名稱:intern,代碼行數:28,代碼來源:Server.ts

示例2: dirname

		return super._resolveConfig().then(() => {
			const config = this.config;

			if (!config.basePath) {
				config.basePath = process.cwd() + sep;
			}

			if (!config.internPath) {
				config.internPath = dirname(dirname(__dirname));
			}
			config.internPath = `${relative(process.cwd(), config.internPath)}${sep}`;

			if (config.reporters.length === 0) {
				config.reporters = [{ reporter: 'simple' }];
			}

			if (!config.nodeSuites) {
				config.nodeSuites = [];
			}

			if (config.benchmarkConfig) {
				config.reporters.push({
					reporter: 'benchmark',
					options: config.benchmarkConfig
				});
			}

			return Promise.all(['suites', 'nodeSuites'].map(property => {
				return expandFiles(config[property]).then(expanded => {
					config[property] = expanded;
				});
			// return void
			})).then(() => null);
		});
開發者ID:bryanforbes,項目名稱:intern,代碼行數:34,代碼來源:Node.ts

示例3: function

		'delay can be reusable': function () {
			const start = Date.now();
			const delay = timing.delay(251);
			const p1 = delay().then(function() {
				assert.approximately(Date.now() - start, 251, 150);
			});
			const p2 = delay('foo').then(function(value) {
				assert.strictEqual(value, 'foo');
				assert.approximately(Date.now() - start, 251, 150);
			});
			const p3 = delay(() => Promise.resolve('bar')).then(function(value) {
				assert.strictEqual(value, 'bar');
				assert.approximately(Date.now() - start, 251, 150);
			});
			return Promise.all([p1, p2, p3]);
		}
開發者ID:bryanforbes,項目名稱:core,代碼行數:16,代碼來源:timing.ts

示例4: loader

		return loader(moduleIds).then((modules: any[]) => {
			pluginResourceIds.forEach((resourceId: string, i: number) => {
				if (typeof resourceId === 'string') {
					const module = modules[i];
					const defaultExport = module['default'] || module;

					if (isPlugin(defaultExport)) {
						resourceId = typeof defaultExport.normalize === 'function' ?
							defaultExport.normalize(resourceId, resolver) :
							resolver(resourceId);

						modules[i] = defaultExport.load(resourceId, load);
					}
				}
			});

			return Promise.all(modules);
		});
開發者ID:bryanforbes,項目名稱:core,代碼行數:18,代碼來源:load.ts

示例5: stop

	stop() {
		const promises: Promise<any>[] = [];

		if (this.server) {
			promises.push(new Promise(resolve => {
				this.server.close(resolve);
			}).then(() => {
				this.server = null;
			}));
		}

		if (this._wsServer) {
			promises.push(new Promise(resolve => {
				this._wsServer.close(resolve);
			}).then(() => {
				this._wsServer = null;
			}));
		}

		return Promise.all(promises).then(() => {
			this._codeCache = null;
		});
	}
開發者ID:bryanforbes,項目名稱:intern,代碼行數:23,代碼來源:Server.ts

示例6: expandFiles

export function expandFiles(patterns?: string[]) {
	if (!Array.isArray(patterns)) {
		patterns = [patterns];
	}
	return Promise.all(patterns.map(pattern => {
		if (glob.hasMagic(pattern)) {
			return new Promise<string[]>((resolve, reject) => {
				glob(pattern, (error, files) => {
					if (error) {
						reject(error);
					}
					else {
						resolve(files);
					}
				});
			});
		}
		return [pattern];
	})).then(fileSets => {
		return fileSets.reduce((allFiles, files) => {
			return allFiles.concat(files);
		}, []);
	});
}
開發者ID:bryanforbes,項目名稱:intern,代碼行數:24,代碼來源:util.ts

示例7: resolve

					operations.push('read2');
					resolve();
				});
			});

			const writePromise2 = new Promise(function (resolve, reject) {
				write(function () {
					operations.push('write2');
					resolve();
				});
			});

			readHandle.destroy();
			writeHandle.destroy();

			return Promise.all([ readPromise1, readPromise2, writePromise1, writePromise2 ]).then(function () {
				assert.deepEqual(operations, [ 'read1', 'read2', 'write1', 'write2' ],
					'Read queue should drain before write, and destroyed items should not run');
			});
		},

		're-destroy'() {
			const handle = read(function () {});
			handle.destroy();
			assert.doesNotThrow(function () {
				handle.destroy();
			});
		}
	},

	order: {
開發者ID:dojo,項目名稱:dom,代碼行數:31,代碼來源:schedule.ts

示例8: _publish

	private _publish(message: Message) {
		const listeners = this._getSession(message.sessionId).listeners;
		return Promise.all(listeners.map(listener => listener(message.name, message.data)));
	}
開發者ID:bryanforbes,項目名稱:intern,代碼行數:4,代碼來源:Server.ts

示例9: catchRejection

		return new Task<DispatchResult>((resolve, reject) => {
			// *Always* start dispatching in a future turn, even if there were no deferrals.
			Promise.all(deferrals).then<DispatchResult>(
				() => {
					// The cancel() function used in the NavigationStartEvent is reused as the Task canceler.
					// Strictly speaking any navstart listener can cancel the dispatch asynchronously, as long as it
					// manages to do so before this turn.
					if (canceled) {
						return { success: false };
					}

					let redirect: undefined | string;
					const dispatched = this._routes.some((route) => {
						const result = route.select(context, segments, trailingSlash, searchParams);

						if (typeof result === 'string') {
							redirect = result;
							return true;
						}
						if (result.length === 0) {
							return false;
						}

						// Update the selected routes after selecting new routes, but before invoking the handlers.
						// This means the original value is available to guard() and params() functions, and the
						// new value when the newly selected routes are executed.
						//
						// Reset selected routes if not dispatched from start().
						this._currentSelection = dispatchFromStart ? result : [];

						for (const { handler, params } of result) {
							catchRejection(this, context, path, handler({ context, params }));
						}

						return true;
					});

					// Reset the selected routes if the dispatch was unsuccessful, or if a redirect was requested.
					if (!dispatched || redirect !== undefined) {
						this._currentSelection = [];
					}

					if (!dispatched && this._fallback) {
						catchRejection(this, context, path, this._fallback({ context, params: {} }));
						return { success: false };
					}

					const result: DispatchResult = { success: dispatched };
					if (redirect !== undefined) {
						result.redirect = redirect;
					}
					return result;
				},
				// When deferrals are canceled their corresponding promise is rejected. Ensure the task resolves
				// with `false` instead of being rejected too.
				() => {
					return { success: false };
				}
			).then(resolve, (error) => {
				reportError(this, context, path, error);
				reject(error);
			});
		}, cancel);
開發者ID:dylans,項目名稱:routing,代碼行數:63,代碼來源:Router.ts


注:本文中的@dojo/shim/Promise.all函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。