runtime¶
effectpy.runtime
¶
Fiber
¶
Bases: Generic[E, A]
A lightweight async task with structured cancellation.
Fibers are effectpy's unit of concurrent execution. Unlike raw asyncio Tasks, fibers provide structured error handling and proper cancellation semantics.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
Task
|
The underlying asyncio task |
required |
name
|
Optional[str]
|
Optional name for debugging |
None
|
Attributes:
Name | Type | Description |
---|---|---|
id |
str
|
Unique identifier for this fiber |
name |
Optional[str]
|
Optional name for debugging |
status |
str
|
Current status ('running', 'done', 'failed', 'cancelled') |
await_()
async
¶
Wait for this fiber to complete and get the structured result.
Returns:
Type | Description |
---|---|
Exit[E, A]
|
Exit containing either the success value or failure cause |
interrupt()
¶
join()
async
¶
Wait for this fiber to complete and get the success value.
Returns:
Type | Description |
---|---|
A
|
The success value if the fiber succeeds |
Raises:
Type | Description |
---|---|
Failure
|
If the fiber fails with a business logic error |
Exception
|
If the fiber dies with an unexpected exception |
Note
This is similar to await_() but throws exceptions instead of returning structured Exit values.
Runtime
¶
Manages effect execution and fiber lifecycle.
Runtime provides advanced features for concurrent execution including fiber management, supervision, and structured error handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
Optional[Context]
|
Base context for all effects (default: empty Context) |
None
|
supervisor
|
Optional[Supervisor]
|
Supervisor for fiber lifecycle callbacks (default: no-op) |
None
|
Example
fork(eff, name=None)
¶
Fork an effect as a new fiber.
The effect starts executing immediately in the background.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eff
|
Effect[Any, E, A]
|
The effect to execute |
required |
name
|
Optional[str]
|
Optional name for debugging |
None
|
Returns:
Type | Description |
---|---|
Fiber[E, A]
|
A Fiber representing the running effect |