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


TypeScript Promise.reject函數代碼示例

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


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

示例1: close

	/**
	 * Signals that the producer is done writing to the stream and wishes to move it to a "closed" state. The stream
	 * may have un-writted data queued; until the data has been written the stream will remain in the "closing" state.
	 */
	close(): Promise<void> {
		// 4.2.4.5-1
		if (!isWritableStream(this)) {
			return Promise.reject(
				new Error('WritableStream method called in context of object that is not a WritableStream instance')
			);
		}

		// 4.2.4.5-2
		if (this.state === State.Closed) {
			return Promise.reject(new TypeError('Stream is already closed'));
		}

		if (this.state === State.Closing) {
			return Promise.reject(new TypeError('Stream is already closing'));
		}

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

		if (this.state === State.Waiting) {
			// 4.2.4.5-4
			this._resolveReadyPromise();
		}

		this._state = State.Closing;
		this._queue.enqueue({ close: true }, 0);
		this._advanceQueue();

		return this._closedPromise;
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:37,代碼來源:WritableStream.ts

示例2: 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

示例3: write

	/**
	 * Enqueue a chunk of data to be written to the underlying sink. `write` can be called successively without waiting
	 * for the previous write's promise to resolve. To respect the stream's backpressure indicator, check if the stream
	 * has entered the "waiting" state between writes.
	 *
	 * @returns A promise that will be fulfilled when the chunk has been written to the underlying sink.
	 */
	write(chunk: T): Promise<void> {
		// 4.2.4.6-1
		if (!isWritableStream(this)) {
			return Promise.reject(
				new Error('WritableStream method called in context of object that is not a WritableStream instance')
			);
		}

		// 4.2.4.6-2
		if (this.state === State.Closed) {
			return Promise.reject(new TypeError('Stream is closed'));
		}

		if (this.state === State.Closing) {
			return Promise.reject(new TypeError('Stream is closing'));
		}

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

		let chunkSize = 1;
		let writeRecord: Record<T> | undefined;
		let promise = new Promise<void>(function (resolve, reject) {
			writeRecord = {
				chunk: chunk,
				reject: reject,
				resolve: resolve
			};
		});
		promise.catch(() => {});

		// 4.2.4.6-6.b
		try {
			if (this._strategy && this._strategy.size) {
				chunkSize = this._strategy.size(chunk);
			}

			this._queue.enqueue(writeRecord, chunkSize);
			this._syncStateWithQueue();
		}
		catch (error) {
			// 4.2.4.6-6.b, 4.2.4.6-10, 4.2.4.6-12
			this._error(error);
			return Promise.reject(error);
		}

		this._advanceQueue();

		return promise;
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:59,代碼來源:WritableStream.ts

示例4: start

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

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

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

示例6: 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

示例7: write

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

		return new Promise<void>((resolve, reject) => {
			this._rejectWritePromise = reject;

			this._nodeStream.write(chunk, this._encoding, (error?: Error) => {
				if (error) {
					this._handleError(error);
				}
				else {
					this._rejectWritePromise = undefined;
					resolve();
				}
			});
		});
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:19,代碼來源:WritableNodeStreamSink.ts

示例8: seek

	seek(position: number): Promise<number> {
		if (this._underlyingSource.seek) {
			return this._underlyingSource.seek(this.controller, position);
		}
		else {
			if (this.reader && position < this.reader.currentPosition) {
				return Promise.reject(new Error('Stream source is not seekable; cannot seek backwards'));
			}
			else {
				let discardNext = (): Promise<number> => {
					return this.reader.read().then((result: ReadResult<T>) => {
						if (result.done || this.reader.currentPosition === position) {
							return Promise.resolve(this.reader.currentPosition);
						}
						else {
							return discardNext();
						}
					});
				};

				return discardNext();
			}
		}
	}
開發者ID:nicknisi,項目名稱:streams,代碼行數:24,代碼來源:SeekableStream.ts

示例9: function

		return function () {
			return Promise.reject(new Error('Unknown loader'));
		};
開發者ID:bryanforbes,項目名稱:core,代碼行數:3,代碼來源:load.ts


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