ManagedRuntime[R, ER]: a layer built once and kept, to run many
effects with its services, as Effect's ManagedRuntime.
The layer is built on first use (or on entering the runtime as a context manager) and shared by every run until the runtime is disposed. Disposal interrupts and awaits the fibers the runtime started, then releases the layer's resources; later runs die.
Built for an application's lifetime, such as a web server's lifespan::
async with ManagedRuntime.make(AppLive) as runtime: # builds AppLive
...
response = await runtime.run_async(handle(request)) # per request
# AppLive's resources are released hereWhere runs go:
run_async/run_async_exit: on the running asyncio loop.run_sync/run_sync_exit: on a scheduler the runtime owns, driven by the calling thread until the effect is done. Sync runs share it, one thread at a time, so fibers the layer forked go on running during each of them.run_fork/run_callback: on the current fiber's run, else the running loop, else the runtime's own scheduler (they then make progress while a sync run ordisposedrives it).
dispose (and a sync with) blocks, so it raises inside a fiber or a
running asyncio loop, whose fibers it could never see finish: use
dispose_effect or dispose_async (async with) there.
| Attribute | Type | Description |
|---|---|---|
R_contra | = TypeVar('R_contra', contravariant=True) | |
ER_co | = TypeVar('ER_co', covariant=True, default=Never) |
Classes#
On This Page
Classes