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


TypeScript Task.then函數代碼示例

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


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

示例1: _sendData

	protected _sendData(name: string, data: any) {
		return this._ready.then(
			() =>
				new Task<void>((resolve, reject) => {
					const id = String(this._sequence++);
					const sessionId = this.sessionId;
					const message: Message = { id, sessionId, name, data };

					this._socket.send(JSON.stringify(message));

					const timer = setTimeout(() => {
						reject(new Error('Send timed out'));
					}, this.timeout);

					this._sendQueue[id] = {
						resolve(data: any) {
							clearTimeout(timer);
							resolve(data);
						},
						reject(error: Error) {
							reject(error);
						}
					};
				})
		);
	}
開發者ID:devpaul,項目名稱:intern,代碼行數:26,代碼來源:WebSocket.ts

示例2: _sendData

	protected _sendData(name: keyof RemoteEvents, data: any) {
		const id = String(this._sequence++);
		const sessionId = this.sessionId;
		const message: Message = { id, sessionId, name, data };

		this._messageBuffer.push(JSON.stringify(message));

		return (this._lastRequest = this._lastRequest.then(() => this._send()));
	}
開發者ID:jason0x43,項目名稱:intern,代碼行數:9,代碼來源:Http.ts

示例3: getConfig

export function getConfig(fileOrArgv?: string | string[], argv?: string[]) {
	let args: { [key: string]: any } = {};
	let file = typeof fileOrArgv === 'string' ? fileOrArgv : undefined;
	argv = Array.isArray(fileOrArgv) ? fileOrArgv : argv;
	const userArgs = (argv || process.argv).slice(2);

	if (process.env['INTERN_ARGS']) {
		mixin(args, parseArgs(parse(process.env['INTERN_ARGS'] || '')));
	}

	if (userArgs.length > 0) {
		mixin(args, parseArgs(userArgs));
	}

	if (file) {
		args.config = file;
	}

	let load: Task<{ [key: string]: any }>;

	if (args.config) {
		// If a config parameter was provided, load it and mix in any other
		// command line args.
		const { configFile, childConfig } = splitConfigPath(args.config, sep);
		file = resolve(configFile || 'intern.json');
		load = loadConfig(file, loadText, args, childConfig);
	} else {
		// If no config parameter was provided, try 'intern.json', or just
		// resolve to the original args
		file = resolve('intern.json');
		load = loadConfig(file, loadText, args, undefined).catch(
			(error: NodeJS.ErrnoException) => {
				if (error.code === 'ENOENT') {
					file = undefined;
					return args;
				}
				throw error;
			}
		);
	}

	return load
		.then(config => {
			// If a basePath wasn't set in the config or via a query arg, and we
			// have a config file path, use that.
			if (file) {
				config.basePath = getBasePath(
					file,
					config.basePath,
					isAbsolute,
					sep
				);
			}
			return config;
		})
		.then(config => ({ config, file }));
}
開發者ID:devpaul,項目名稱:intern,代碼行數:57,代碼來源:util.ts

示例4:

			(resolve, reject) => {
				this._messageBuffer.push({
					message: JSON.stringify(message),
					resolve,
					reject
				});

				if (this._activeRequest) {
					this._activeRequest.then(() => this._sendMessages());
				} else {
					this._sendMessages();
				}
			},
開發者ID:gitgrimbo,項目名稱:intern,代碼行數:13,代碼來源:Http.ts

示例5: _sendData

	protected _sendData(name: keyof RemoteEvents, data: any) {
		const id = String(this._sequence++);
		const sessionId = this.sessionId;
		const message: Message = { id, sessionId, name, data };

		this._messageBuffer.push(JSON.stringify(message));

		if (this._activeRequest || this._pendingRequest) {
			if (!this._pendingRequest) {
				// Schedule another request after the active one completes
				this._pendingRequest = this._activeRequest.then(() => {
					this._pendingRequest = null;
					return this._send();
				});
			}
			return this._pendingRequest;
		}

		return this._send();
	}
開發者ID:bryanforbes,項目名稱:intern,代碼行數:20,代碼來源:Http.ts


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