当前位置: 首页>>代码示例>>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;未经允许,请勿转载。