提交 12479612 编写于 作者: J Joao Moreno

cleanup more async/await

related to #53442
上级 76d28c91
......@@ -442,13 +442,13 @@ export function sequence<T>(promiseFactories: ITask<Thenable<T>>[]): TPromise<T[
return TPromise.as(null).then(thenHandler);
}
export function first<T>(promiseFactories: ITask<TPromise<T>>[], shouldStop: (t: T) => boolean = t => !!t): TPromise<T> {
export function first<T>(promiseFactories: ITask<TPromise<T>>[], shouldStop: (t: T) => boolean = t => !!t, defaultValue: T = null): TPromise<T> {
let index = 0;
const len = promiseFactories.length;
const loop: () => TPromise<T> = () => {
if (index >= len) {
return TPromise.as(null);
return TPromise.as(defaultValue);
}
const factory = promiseFactories[index++];
......
......@@ -9,6 +9,7 @@ import { IURLService, IURLHandler } from 'vs/platform/url/common/url';
import URI from 'vs/base/common/uri';
import { IDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { TPromise } from 'vs/base/common/winjs.base';
import { first } from 'vs/base/common/async';
declare module Array {
function from<T>(set: Set<T>): T[];
......@@ -20,16 +21,9 @@ export class URLService implements IURLService {
private handlers = new Set<IURLHandler>();
async open(uri: URI): TPromise<boolean> {
open(uri: URI): TPromise<boolean> {
const handlers = Array.from(this.handlers);
for (const handler of handlers) {
if (await handler.handleURL(uri)) {
return true;
}
}
return false;
return first(handlers.map(h => () => h.handleURL(uri)), undefined, false);
}
registerHandler(handler: IURLHandler): IDisposable {
......@@ -44,7 +38,7 @@ export class RelayURLService extends URLService implements IURLHandler {
super();
}
async open(uri: URI): TPromise<boolean> {
open(uri: URI): TPromise<boolean> {
return this.urlService.open(uri);
}
......
......@@ -66,10 +66,10 @@ export class DebugViewlet extends ViewContainerViewlet {
}));
}
async create(parent: HTMLElement): TPromise<void> {
await super.create(parent);
DOM.addClass(parent, 'debug-viewlet');
create(parent: HTMLElement): TPromise<void> {
return super.create(parent).then(() => {
DOM.addClass(parent, 'debug-viewlet');
});
}
public focus(): void {
......
......@@ -173,10 +173,10 @@ export class ExplorerViewlet extends ViewContainerViewlet implements IExplorerVi
this._register(this.contextService.onDidChangeWorkspaceName(e => this.updateTitleArea()));
}
async create(parent: HTMLElement): TPromise<void> {
await super.create(parent);
DOM.addClass(parent, 'explorer-viewlet');
create(parent: HTMLElement): TPromise<void> {
return super.create(parent).then(() => {
DOM.addClass(parent, 'explorer-viewlet');
});
}
protected createView(viewDescriptor: IViewDescriptor, options: IViewletViewOptions): ViewletPanel {
......
......@@ -160,7 +160,7 @@ export class ReleaseNotesManager {
return body;
}
private async renderContent(text: string): TPromise<string> {
private async renderContent(text: string): Promise<string> {
const renderer = await this.getRenderer(text);
return marked(text, { renderer });
}
......
......@@ -27,11 +27,11 @@ export class OpenUrlAction extends Action {
super(id, label);
}
async run(): TPromise<any> {
const input = await this.quickInputService.input({ prompt: 'URL to open' });
const uri = URI.parse(input);
this.urlService.open(uri);
run(): TPromise<any> {
return this.quickInputService.input({ prompt: 'URL to open' }).then(input => {
const uri = URI.parse(input);
this.urlService.open(uri);
});
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册