Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(waitForEvent): refactor waitForEvent into a single implementati…
…on (#1602) Moves the `waitForEvent` implementation into an `ExtendedEventEmitter` class. This is step one if we want to add `waitForEvent` to `Worker`, `Browser`, and `BrowserServer` objects. All of these only have a 'close' event, but I still feel we should be consistent with our event emitters.
- Loading branch information
1 parent
314eb40
commit 9e85f8d
Showing
3 changed files
with
56 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { EventEmitter } from './platform'; | ||
import { helper } from './helper'; | ||
|
||
export class ExtendedEventEmitter extends EventEmitter { | ||
protected _abortPromiseForEvent(event: string) { | ||
return new Promise<Error>(() => void 0); | ||
} | ||
|
||
protected _timeoutForEvent(event: string): number { | ||
throw new Error('unimplemented'); | ||
} | ||
|
||
async waitForEvent(event: string, optionsOrPredicate: Function|{ predicate?: Function, timeout?: number } = {}): Promise<any> { | ||
const { | ||
predicate = () => true, | ||
timeout = this._timeoutForEvent(event) | ||
} = typeof optionsOrPredicate === 'function' ? {predicate: optionsOrPredicate} : optionsOrPredicate; | ||
return helper.waitForEvent(this, event, predicate, timeout, this._abortPromiseForEvent(event)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters