feat(plugin): add promise plugin cleanup
This commit is contained in:
@@ -25,6 +25,15 @@ export default Plugin.define({
|
||||
```
|
||||
|
||||
Plugin setup registers hooks imperatively through each domain's `hook` method.
|
||||
It may return a synchronous or asynchronous cleanup function. OpenCode awaits
|
||||
the cleanup when the plugin is unloaded or replaced:
|
||||
|
||||
```ts
|
||||
setup: async (ctx) => {
|
||||
const timer = setInterval(refresh, 60_000)
|
||||
return () => clearInterval(timer)
|
||||
}
|
||||
```
|
||||
|
||||
Configuration supplied for the plugin is available as `ctx.options`.
|
||||
|
||||
|
||||
@@ -26,9 +26,11 @@ export interface Context {
|
||||
readonly tool: ToolDomain
|
||||
}
|
||||
|
||||
export type Cleanup = () => Promise<void> | void
|
||||
|
||||
export interface Plugin {
|
||||
readonly id: string
|
||||
readonly setup: (context: Context) => Promise<void> | void
|
||||
readonly setup: (context: Context) => Promise<Cleanup | void> | Cleanup | void
|
||||
}
|
||||
|
||||
export function define(plugin: Plugin) {
|
||||
|
||||
Reference in New Issue
Block a user