mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2026-08-29 02:24:35 -05:00
* Enable PEP604 Ruff rules * Fix harcoded signature in test * Hack CLVMStreamable test with note to fast follow
28 lines
691 B
Python
28 lines
691 B
Python
# Package: utils
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Callable
|
|
from concurrent.futures import Executor, Future
|
|
from typing import TypeVar
|
|
|
|
_T = TypeVar("_T")
|
|
|
|
|
|
class InlineExecutor(Executor):
|
|
_closing: bool = False
|
|
|
|
def submit(self, fn: Callable[..., _T], *args, **kwargs) -> Future[_T]: # type: ignore
|
|
if self._closing:
|
|
raise RuntimeError("executor shutting down")
|
|
|
|
f: Future[_T] = Future()
|
|
try:
|
|
f.set_result(fn(*args, **kwargs))
|
|
except BaseException as e: # lgtm[py/catch-base-exception]
|
|
f.set_exception(e)
|
|
return f
|
|
|
|
def close(self) -> None:
|
|
self._closing = True
|