Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/beige-socks-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": minor
---

implement `Symbol.dispose` and `Symbol.asyncDisposable` for ManagedRuntime
9 changes: 9 additions & 0 deletions packages/effect/src/ManagedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ export interface ManagedRuntime<in R, out ER> extends Effect.Effect<Runtime.Runt
*/
readonly disposeEffect: Effect.Effect<void, never, never>

/**
* Dispose of the resources associated with the runtime.
*/
[Symbol.dispose](): void
/**
* Dispose of the resources associated with the runtime.
*/
[Symbol.asyncDispose](): Promise<void>

readonly [Unify.typeSymbol]?: unknown
readonly [Unify.unifySymbol]?: ManagedRuntimeUnify<this>
readonly [Unify.ignoreSymbol]?: ManagedRuntimeUnifyIgnore
Expand Down
6 changes: 6 additions & 0 deletions packages/effect/src/internal/managedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export const make = <R, ER>(
self.cachedRuntime = undefined
return Scope.close(self.scope, core.exitVoid)
}),
[Symbol.dispose](): void {
internalRuntime.unsafeRunEffect(self.disposeEffect)
},
[Symbol.asyncDispose](): Promise<void> {
return self.dispose()
},
runFork<A, E>(effect: Effect.Effect<A, E, R>, options?: Runtime.RunForkOptions): Fiber.RuntimeFiber<A, E | ER> {
return self.cachedRuntime === undefined ?
internalRuntime.unsafeForkEffect(provide(self, effect), options) :
Expand Down