• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Promise.all函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中dojo-shim/Promise.all函数的典型用法代码示例。如果您正苦于以下问题:TypeScript all函数的具体用法?TypeScript all怎么用?TypeScript all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了all函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

	'should generate unique ids': function(this: any) {
		const ids: Promise<string>[] = [];
		const store =  createStore();
		const generateNIds = 100000;
		for (let i = 0; i < generateNIds; i++) {
			ids.push(store.createId());
		}
		Promise.all(ids).then(function(ids) {
			assert.equal(new Set(ids).size, generateNIds, 'Not all generated IDs were unique');
		});
	},
开发者ID:maier49,项目名称:store,代码行数:11,代码来源:createStore.ts


示例2: createWidget

					{
						name: 'foo-bar',
						factory: () => expected['foo-bar']
					},
					{
						name: 'baz-qux',
						factory: () => expected['baz-qux']
					}
				]
			});

			assert.isTrue(app.hasCustomElementFactory('foo-bar'));
			assert.isTrue(app.hasCustomElementFactory('baz-qux'));

			return Promise.all([
				app.getCustomElementFactory('foo-bar')(),
				app.getCustomElementFactory('baz-qux')()
			]).then(([fooBar, bazQux]) => {
				assert.strictEqual(fooBar, expected['foo-bar']);
				assert.strictEqual(bazQux, expected['baz-qux']);
			});
		},

		'factory can be a module identifier'() {
			const expected = createWidget();
			stubWidgetFactory(() => expected);

			const app = createApp({ toAbsMid });
			app.loadDefinition({
				customElements: [
					{
						name: 'foo-bar',
开发者ID:datafordevelopment,项目名称:dojo-frame,代码行数:32,代码来源:customElements.ts


示例3: 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:jdonaghue,项目名称:dom,代码行数:31,代码来源:schedule.ts


示例4: createInMemoryStorage

			assert.deepEqual(storage.identify(createData()), ['1', '2', '3']);
		},
		'Should accept identifying a single item.'(this: any) {
			const storage = createInMemoryStorage();
			assert.deepEqual(storage.identify(createData()[2]), ['3']);
		}
	},

	'createId'() {
		const storage = createInMemoryStorage();
		const ids: Promise<string>[] = [];
		const generateNIds = 100000;
		for (let i = 0; i < generateNIds; i++) {
			ids.push(storage.createId());
		}
		Promise.all(ids).then(function(ids) {
			assert.equal(new Set(ids).size, generateNIds, 'Not all generated IDs were unique');
		});
	},

	'add': {
		'Should add new items into storage.'(this: any) {
			const { dfd, storage, data } = getStorageAndDfd(this);

			storage.add(data).then(function(result) {
				assert.deepEqual(result.successfulData, createData());
			}).then(dfd.resolve);
		},
		'Should return a result of type Add.'(this: any) {
			const { dfd, storage, data } = getStorageAndDfd(this);
开发者ID:maier49,项目名称:store,代码行数:30,代码来源:createInMemoryStorage.ts


示例5: 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 };
						}

						const { fallback, routes } = state;
						let redirect: undefined | string;
						const dispatched = 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().
							state.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) {
							state.currentSelection = [];
						}

						if (!dispatched && fallback) {
							catchRejection(this, context, path, 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:jdonaghue,项目名称:routing,代码行数:64,代码来源:createRouter.ts



注:本文中的dojo-shim/Promise.all函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript Promise.reject函数代码示例发布时间:2022-05-25
下一篇:
TypeScript Map.set函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap