suned / pfun

Functional, composable, asynchronous, type-safe Python.
https://pfun.dev/
MIT License
151 stars 14 forks source link

Allow global thread and process pool executors #106

Open suned opened 2 years ago

suned commented 2 years ago

Currently each effect is interpreted using its own process and thread pools. It would be preferable to enable the caller to control the lifecycle of these pools. Concretely, we could change the signature of functions that introduce the dependency on a thread or process pool to e.g:

def from_cpu_bound_callable(f: Callable[[R], Either[E, A]]) -> Effect[Intersection[R, HasProcessPool], E, A]: ...

Where HasProcessPool is defined as:

from typing import Protocol

class HasProcessPool(Protocol):
    pool: ProcessPoolExecutor