本文整理匯總了TypeScript中@orbit/core.Promise類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Promise類的具體用法?TypeScript Promise怎麽用?TypeScript Promise使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Promise類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: jsonapiResponse
export function jsonapiResponse(_options, body?, timeout?) {
let options;
let response;
if (typeof _options === 'number') {
options = { status: _options };
} else {
options = _options || {};
}
options.statusText = options.statusText || statusText(options.status);
options.headers = options.headers || {};
if (body) {
options.headers['Content-Type'] = 'application/vnd.api+json';
response = new Orbit.globals.Response(JSON.stringify(body), options);
} else {
response = new Orbit.globals.Response(options);
}
// console.log('jsonapiResponse', body, options, response.headers.get('Content-Type'));
if (timeout) {
return new Orbit.Promise((resolve, reject) => {
let timer = Orbit.globals.setTimeout(() => {
Orbit.globals.clearTimeout(timer);
resolve(response);
}, timeout);
});
} else {
return Orbit.Promise.resolve(response);
}
}
示例2: removeItem
removeItem(key: string): Promise<void> {
const fullKey: string = this.getFullKeyForItem(key);
Orbit.globals.localStorage.removeItem(fullKey);
return Orbit.Promise.resolve();
}
示例3: setItem
setItem(key: string, value: any): Promise<void> {
const fullKey: string = this.getFullKeyForItem(key);
Orbit.globals.localStorage.setItem(fullKey, JSON.stringify(value));
return Orbit.Promise.resolve();
}
示例4: getItem
getItem(key: string): Promise<any> {
const fullKey: string = this.getFullKeyForItem(key);
return Orbit.Promise.resolve(JSON.parse(Orbit.globals.localStorage.getItem(fullKey)));
}
示例5: upgrade
upgrade() {
assert.ok(false, 'upgrade should not be called');
return Orbit.Promise.resolve();
}