feat(plugin): add dispose hook (#29493)
This commit is contained in:
parent
a78605f8ea
commit
519d344470
2 changed files with 15 additions and 0 deletions
|
|
@ -244,6 +244,20 @@ export const layer = Layer.effect(
|
||||||
}).pipe(Effect.ignore)
|
}).pipe(Effect.ignore)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yield* Effect.addFinalizer(() =>
|
||||||
|
Effect.forEach(
|
||||||
|
hooks,
|
||||||
|
(hook) =>
|
||||||
|
Effect.tryPromise({
|
||||||
|
try: () => Promise.resolve(hook.dispose?.()),
|
||||||
|
catch: (error) => {
|
||||||
|
log.error("plugin dispose hook failed", { error })
|
||||||
|
},
|
||||||
|
}).pipe(Effect.ignore),
|
||||||
|
{ discard: true },
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
// Subscribe to bus events, fiber interrupted when scope closes
|
// Subscribe to bus events, fiber interrupted when scope closes
|
||||||
yield* (yield* bus.subscribeAll()).pipe(
|
yield* (yield* bus.subscribeAll()).pipe(
|
||||||
Stream.runForEach((input) =>
|
Stream.runForEach((input) =>
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,7 @@ export type ProviderHook = {
|
||||||
export type AuthOuathResult = AuthOAuthResult
|
export type AuthOuathResult = AuthOAuthResult
|
||||||
|
|
||||||
export interface Hooks {
|
export interface Hooks {
|
||||||
|
dispose?: () => Promise<void>
|
||||||
event?: (input: { event: Event }) => Promise<void>
|
event?: (input: { event: Event }) => Promise<void>
|
||||||
config?: (input: Config) => Promise<void>
|
config?: (input: Config) => Promise<void>
|
||||||
tool?: {
|
tool?: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue