Skip to content

Commit

Permalink
feat: add shutdown hook (#3234)
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni authored May 23, 2023
1 parent e271998 commit fbaac57
Showing 1 changed file with 7 additions and 2 deletions.
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 @@ -213,6 +214,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 @@ -838,7 +840,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 @@ -855,7 +857,10 @@ class Compiler {
});
return;
}
callback();
this.hooks.shutdown.callAsync(err => {
if (err) return callback(err);
this.cache.shutdown(callback);
});
}

getAsset(name: string) {
Expand Down

0 comments on commit fbaac57

Please sign in to comment.