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


TypeScript ts-promise.Promise類代碼示例

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


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

示例1:

			(abortError: Error) => {
				// Abort pending read, if necessary
				if (this._resumer) {
					this._resumer(Promise.reject(abortError));
					this._resumer = undefined;
				}
			}
開發者ID:BuddyPlatform,項目名稱:ts-stream,代碼行數:7,代碼來源:node.ts

示例2:

			(enderError: Error) => {
				// ender callback failed, but in order to let final stream fail,
				// we need to pass 'something' on, and to wait for that to come
				// back.
				// Finally, make sure to return the enderError.
				return Promise.resolve(defaultEnder(error || enderError)).then(
					() => Promise.reject(enderError),
					() => Promise.reject(enderError)
				);
			}
開發者ID:BuddyPlatform,項目名稱:ts-stream,代碼行數:10,代碼來源:Transform.ts

示例3: filterer

		(v: T): void|Promise<void> => {
			var b = filterer(v);
			if (!b) {
				return;
			} else if (b === true) { // note: not just `if (b)`!
				return writable.write(v);
			} else { // more complex return type, probably a Thenable
				return Promise.resolve(b).then((resolvedB) => {
					if (resolvedB) {
						return writable.write(v);
					}
				});
			}
		},
開發者ID:BuddyPlatform,項目名稱:ts-stream,代碼行數:14,代碼來源:Transform.ts

示例4: return

	return (error?: Error) => {
		// TODO: an error returned from ender is currently passed on to next
		// stream, if stream was not ended with an error yet.
		// It'd maybe be better to not have the next stream be ended when an
		// error occurred in this ender, but there's no way to send another
		// end(), so we have to close it somehow...
		return Promise.resolve(error).then(ender).then(
			() => defaultEnder(error),
			(enderError: Error) => {
				// ender callback failed, but in order to let final stream fail,
				// we need to pass 'something' on, and to wait for that to come
				// back.
				// Finally, make sure to return the enderError.
				return Promise.resolve(defaultEnder(error || enderError)).then(
					() => Promise.reject(enderError),
					() => Promise.reject(enderError)
				);
			}
		);
	};
開發者ID:BuddyPlatform,項目名稱:ts-stream,代碼行數:20,代碼來源:Transform.ts

示例5: Error

 .catch(function(){
     console.log("error");
     return Promise.reject(new Error("Error login"));
 })
開發者ID:tsonevn,項目名稱:Angular2-Sample-Project,代碼行數:4,代碼來源:app.component.ts

示例6:

export const resolveGlobs = (globs: string[]) : Promise<string[]> => {
    return Promise.all(globs.map(pglob)).then(x=> flatten<string>(x));
};
開發者ID:OctopusDeploy,項目名稱:OctoTFS,代碼行數:3,代碼來源:inputs.ts

示例7: Promise

"use strict";

import { Promise } from "ts-promise";


var prom = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve(42);
        // or e.g.: reject(new Error("boom"));
    }, 100);
});



/// Hello world
Promise.resolve("test").then((v) => {
	console.log(v);
});

var p = Promise.resolve();

/*
Promise.setLongTraces(true);
var p = Promise.resolve();
p.then(() => {
	//return Promise.reject(new Error("my error"));
}).catch((e) => {
	console.error(e.stack);
});
*/
開發者ID:duffman,項目名稱:packman,代碼行數:30,代碼來源:promise.ts


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