disposable
Ties a Disposable or an AsyncDisposable to the lifetime of any Obsidian Component, a Plugin included.
ComponentEx.registerDisposable and ComponentEx.registerAsyncDisposable delegate here, so the free functions and the methods cannot diverge. They exist as free functions because no plugin base class extends ComponentEx.
Functions
Section titled “Functions”| Function | Description |
|---|---|
| registerAsyncDisposable | Registers an AsyncDisposable so its disposal starts when the component unloads, and returns it unchanged. Obsidian’s unload is synchronous, so nothing awaits the disposal. When the component is a Plugin, the disposal is tracked under the plugin id, and the plugin’s next instance (a PluginBase one) waits for it before it loads, as PluginBase.registerAsyncCleanup does. On any other component the disposal runs detached, and a failure is reported, never rethrown. |
| registerDisposable | Registers a Disposable so it is disposed when the component unloads, and returns it unchanged. The recurring “tie a disposable to the component’s lifecycle, then keep using it” idiom, for any component: registerDisposable(plugin, await registerVirtualFile(...)). The disposable is disposed on Component.unload, or earlier if the caller disposes it directly, since disposal is expected to be idempotent. A component that is never loaded never unloads, so its registered disposables are never disposed. |