• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript Promise.resolve函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript has.add函数代码示例发布时间:2022-05-28
下一篇:
TypeScript Promise.reject函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap