Files
chia-blockchain/chia/util/inline_executor.py
Matt HauffandGitHub 40db4635a8 [LABS-245] Enable PEP604 Ruff rules (#20269)
* Enable PEP604 Ruff rules

* Fix harcoded signature in test

* Hack CLVMStreamable test with note to fast follow
2025-11-18 12:34:00 -08:00

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