Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shutdown hook #3234

Merged
merged 1 commit into from
May 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/rspack/src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Compiler {
emit: tapable.AsyncSeriesHook<[Compilation]>;
afterEmit: tapable.AsyncSeriesHook<[Compilation]>;
failed: tapable.SyncHook<[Error]>;
shutdown: tapable.AsyncSeriesHook<[]>;
watchRun: tapable.AsyncSeriesHook<[Compiler]>;
watchClose: tapable.SyncHook<[]>;
environment: tapable.SyncHook<[]>;
Expand Down Expand Up @@ -212,6 +213,7 @@ class Compiler {
compile: new SyncHook(["params"]),
infrastructureLog: new SyncBailHook(["origin", "type", "args"]),
failed: new SyncHook(["error"]),
shutdown: new tapable.AsyncSeriesHook([]),
normalModuleFactory: new tapable.SyncHook<NormalModuleFactory>([
"normalModuleFactory"
]),
Expand Down Expand Up @@ -803,7 +805,7 @@ class Compiler {
}
}

close(callback: () => void) {
close(callback: (error?: Error | null) => void) {
// WARNING: Arbitrarily dropping the instance is not safe, as it may still be in use by the background thread.
// A hint is necessary for the compiler to know when it is safe to drop the instance.
// For example: register a callback to the background thread, and drop the instance when the callback is called (calling the `close` method queues the signal)
Expand All @@ -820,7 +822,10 @@ class Compiler {
});
return;
}
callback();
this.hooks.shutdown.callAsync(err => {
if (err) return callback(err);
this.cache.shutdown(callback);
});
}

getAsset(name: string) {
Expand Down