feat(plugin): add promise plugin cleanup
This commit is contained in:
parent
278c510549
commit
c867e66ab5
6 changed files with 74 additions and 15 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue