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


TypeScript Promise.resolve函數代碼示例

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


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

示例1: constructor

	constructor(underlyingSink: Sink<T> = {}, strategy: Strategy<T> = {}) {
		this._underlyingSink = underlyingSink;

		this._closedPromise = new Promise<void>((resolve, reject) => {
			this._resolveClosedPromise = resolve;
			this._rejectClosedPromise = reject;
		});

		this._closedPromise.catch(() => {});

		this._advancing = false;
		this._readyPromise = Promise.resolve();
		this._queue = new SizeQueue<Record<T>>();
		this._state = State.Writable;
		this._started = false;
		this._writing = false;
		this._strategy = util.normalizeStrategy(strategy);
		this._syncStateWithQueue();

		this._startedPromise = Promise.resolve(
			util.invokeOrNoop(this._underlyingSink, 'start', [ this._error.bind(this) ])
		).then(() => {
			this._started = true;
			this._startedPromise = undefined;
		}, (error: Error) => {
			this._error(error);
		});
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:28,代碼來源:WritableStream.ts

示例2: start

	start(): Promise<void> {
		if (this._isClosed) {
			return Promise.reject(new Error('Stream is closed'));
		}

		return Promise.resolve();
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:7,代碼來源:WritableNodeStreamSink.ts

示例3: abort

	/**
	 * Signals that the producer can no longer write to the stream and it should be immediately moved to an "errored"
	 * state. Any un-written data that is queued will be discarded.
	 */
	abort(reason: any): Promise<void> {
		// 4.2.4.4-1
		if (!isWritableStream(this)) {
			return Promise.reject(
				new Error('WritableStream method called in context of object that is not a WritableStream instance')
			);
		}

		if (this.state === State.Closed) {
			// 4.2.4.4-2
			return Promise.resolve();
		}

		if (this.state === State.Errored) {
			// 4.2.4.4-3
			return Promise.reject(this._storedError);
		}

		const error: Error = reason instanceof Error ? reason : new Error(reason);

		this._error(error);

		return util.promiseInvokeOrFallbackOrNoop(this._underlyingSink, 'abort', [ reason ], 'close')
			.then(function () {
				return;
			});
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:31,代碼來源:WritableStream.ts

示例4: catchRejection

function catchRejection(router: Router<Context>, context: Context, path: string, thenable: void | Thenable<any>) {
	if (thenable) {
		Promise.resolve(thenable).catch((error) => {
			reportError(router, context, path, error);
		});
	}
}
開發者ID:dylans,項目名稱:routing,代碼行數:7,代碼來源:Router.ts

示例5: discardNext

					return this.reader.read().then((result: ReadResult<T>) => {
						if (result.done || this.reader.currentPosition === position) {
							return Promise.resolve(this.reader.currentPosition);
						}
						else {
							return discardNext();
						}
					});
開發者ID:nicknisi,項目名稱:streams,代碼行數:8,代碼來源:SeekableStream.ts

示例6: readNext

				return reader.read().then(function (result: ReadResult<number>) {
					if (result.done) {
						return Promise.resolve();
					}
					else {
						results.push(result.value);
						return readNext();
					}
				});
開發者ID:nicknisi,項目名稱:streams,代碼行數:9,代碼來源:TransformStream.ts

示例7: pluginLoad

			return pluginLoad(moduleIds, load, (moduleIds: string[]) => {
				try {
					return Promise.resolve(moduleIds.map(function (moduleId): any {
						return contextualRequire(moduleId.split('!')[0]);
					}));
				}
				catch (error) {
					return Promise.reject(error);
				}
			});
開發者ID:bryanforbes,項目名稱:core,代碼行數:10,代碼來源:load.ts

示例8: seek

	seek(controller: ReadableStreamController<T>, position: number): Promise<number> {
		if (position >= this.data.length || position < 0) {
			let error = new Error('Invalid seek position: ' + position);
			controller.error(error);

			return Promise.reject(error);
		}

		this.currentPosition = position;

		return Promise.resolve(this.currentPosition);
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:12,代碼來源:ArraySource.ts

示例9: Error

import Promise from '@dojo/shim/Promise';
import { Source } from './ReadableStream';
import ReadableStreamController from './ReadableStreamController';

const resolved = Promise.resolve();

/**
 * A seekable array source
 */
export default class ArraySource<T> implements Source<T> {
	// current seek position in the data array
	currentPosition: number;

	// shallow copy of data array passed to constructor
	data: Array<T>;

	constructor(data: Array<T>) {
		this.currentPosition = 0;
		this.data = [];

		if (data && data.length) {
			this.data = this.data.concat(data);
		}
	}

	seek(controller: ReadableStreamController<T>, position: number): Promise<number> {
		if (position >= this.data.length || position < 0) {
			let error = new Error('Invalid seek position: ' + position);
			controller.error(error);

			return Promise.reject(error);
開發者ID:nicknisi,項目名稱:streams,代碼行數:31,代碼來源:ArraySource.ts

示例10: write

	write(chunk: string): Promise<void> {
		return Promise.resolve();
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:3,代碼來源:BaseStringSink.ts


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