summaryrefslogtreecommitdiff
path: root/src/apscheduler/executors/async_.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/apscheduler/executors/async_.py')
-rw-r--r--src/apscheduler/executors/async_.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/apscheduler/executors/async_.py b/src/apscheduler/executors/async_.py
new file mode 100644
index 0000000..c7924ad
--- /dev/null
+++ b/src/apscheduler/executors/async_.py
@@ -0,0 +1,24 @@
+from __future__ import annotations
+
+from collections.abc import Callable
+from inspect import isawaitable
+from typing import Any
+
+from .._structures import Job
+from ..abc import JobExecutor
+
+
+class AsyncJobExecutor(JobExecutor):
+ """
+ Executes functions directly on the event loop thread.
+
+ If the function returns a coroutine object (or another kind of awaitable), that is
+ awaited on and its return value is used as the job's return value.
+ """
+
+ async def run_job(self, func: Callable[..., Any], job: Job) -> Any:
+ retval = func(*job.args, **job.kwargs)
+ if isawaitable(retval):
+ retval = await retval
+
+ return retval