Implementation:Microsoft Playwright ManualPromise
Appearance
Overview
ManualPromise extends the native Promise class with externally accessible resolve() and reject() methods, providing a deferred pattern for async coordination throughout Playwright.
Description
The module provides two classes:
ManualPromise<T>-- a Promise subclass that exposesresolve()andreject()as instance methods, along with anisDone()check. It usesSymbol.speciesto ensure derived promises (from.then()) are standard Promises.
LongStandingScope-- manages a collection of races (ManualPromises) that can all be terminated simultaneously, useful for managing cancellation of multiple concurrent operations tied to a single lifecycle scope.
Usage
Used extensively throughout Playwright for async coordination, progress tracking, and lifecycle management where the resolve/reject decision is external to the promise creation.
Code Reference
Source Location
packages/playwright-core/src/utils/isomorphic/manualPromise.ts (122 lines)
Class Signatures
export class ManualPromise<T = void> extends Promise<T> {
constructor()
isDone(): boolean
resolve(t: T): void
reject(e: Error): void
}
export class LongStandingScope {
isClosed(): boolean
close(error: Error): void
race<T>(promise: Promise<T>): Promise<T>
}
Import
import { ManualPromise, LongStandingScope } from '../utils/isomorphic/manualPromise';
I/O Contract
ManualPromise
- Created without arguments
resolve(value)andreject(error)can be called externallyisDone()returns true after resolve or reject
LongStandingScope
race(promise)-- wraps a promise that will be rejected if the scope is closedclose(error)-- terminates all pending races with the given error
Usage Examples
Basic Usage
const promise = new ManualPromise<string>();
// ... later, from another context:
promise.resolve('done');
const result = await promise; // 'done'
Related Pages
- Microsoft_Playwright_ProgressController -- Uses ManualPromise for abort handling
- Microsoft_Playwright_LocalUtils -- Uses ManualPromise for zip creation
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment