本文整理匯總了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');
});
},
示例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',
示例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: {
示例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);
示例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);