本文整理汇总了TypeScript中@theintern/common.CancellablePromise类的典型用法代码示例。如果您正苦于以下问题:TypeScript CancellablePromise类的具体用法?TypeScript CancellablePromise怎么用?TypeScript CancellablePromise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CancellablePromise类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getConfig
export function getConfig(
fileOrArgv?: string | string[],
argv?: string[]
): CancellablePromise<{ config: any; file?: 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']) {
Object.assign(args, parseArgs(parse(process.env['INTERN_ARGS'] || '')));
}
if (userArgs.length > 0) {
Object.assign(args, parseArgs(userArgs));
}
if (file) {
args.config = file;
}
let load: CancellablePromise<{ [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:edhager,项目名称:intern,代码行数:55,代码来源:util.ts
示例2: _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:edhager,项目名称:intern,代码行数:26,代码来源:WebSocket.ts
示例3:
(resolve, reject) => {
this._messageBuffer.push({
message: JSON.stringify(message),
resolve,
reject
});
if (this._activeRequest) {
this._activeRequest.then(() => this._sendMessages());
} else {
this._sendMessages();
}
},
开发者ID:edhager,项目名称:intern,代码行数:13,代码来源:Http.ts
注:本文中的@theintern/common.CancellablePromise类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论