refactor(ngcc): add support for asynchronous execution (#32427)
Previously, `ngcc`'s programmatic API would run and complete synchronously. This was necessary for specific usecases (such as how the `@angular/cli` invokes `ngcc` as part of the TypeScript module resolution process), but not for others (e.g. running `ivy-ngcc` as a `postinstall` script). This commit adds a new option (`async`) that enables turning on asynchronous execution. I.e. it signals that the caller is OK with the function call to complete asynchronously, which allows `ngcc` to potentially run in a more efficient mode. Currently, there is no difference in the way tasks are executed in sync vs async mode, but this change sets the ground for adding new execution options (that require asynchronous operation), such as processing tasks in parallel on multiple processes. NOTE: When using the programmatic API, the default value for `async` is `false`, thus retaining backwards compatibility. When running `ngcc` from the command line (i.e. via the `ivy-ngcc` script), it runs in async mode (to be able to take advantage of future optimizations), but that is transparent to the caller. PR Close #32427
This commit is contained in:

committed by
Matias Niemelä

parent
5c213e5474
commit
3127ba3c35
@ -33,7 +33,7 @@ export interface ExecutionOptions {
|
||||
export interface Executor {
|
||||
execute(
|
||||
analyzeEntryPoints: AnalyzeEntryPointsFn, createCompileFn: CreateCompileFn,
|
||||
options: ExecutionOptions): void;
|
||||
options: ExecutionOptions): void|Promise<void>;
|
||||
}
|
||||
|
||||
/** Represents metadata related to the processing of an entry-point. */
|
||||
|
@ -44,3 +44,12 @@ export class SingleProcessExecutor implements Executor {
|
||||
checkForUnprocessedEntryPoints(processingMetadataPerEntryPoint, options.propertiesToConsider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An `Executor` that processes all tasks serially, but still completes asynchronously.
|
||||
*/
|
||||
export class AsyncSingleProcessExecutor extends SingleProcessExecutor {
|
||||
async execute(...args: Parameters<Executor['execute']>): Promise<void> {
|
||||
return super.execute(...args);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user