mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-31 05:15:32 +00:00
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)
|
||||
}
|
||||
|
||||
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
|
||||
yield* (yield* bus.subscribeAll()).pipe(
|
||||
Stream.runForEach((input) =>
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ export type ProviderHook = {
|
|||
export type AuthOuathResult = AuthOAuthResult
|
||||
|
||||
export interface Hooks {
|
||||
dispose?: () => Promise<void>
|
||||
event?: (input: { event: Event }) => Promise<void>
|
||||
config?: (input: Config) => Promise<void>
|
||||
tool?: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue