Skip to content

Commit 672b1a1

Browse files
re-enable the batch API
Signed-off-by: Achille Roussel <[email protected]>
1 parent 8487159 commit 672b1a1

File tree

2 files changed

+8
-369
lines changed

2 files changed

+8
-369
lines changed

src/dispatch/function.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,10 @@ def _register(self, name: str, wrapped_func: PrimitiveFunction):
330330
raise ValueError(f"function already registered with name '{name}'")
331331
self.functions[name] = wrapped_func
332332

333-
def batch(self): # -> Batch:
333+
def batch(self) -> Batch:
334334
"""Returns a Batch instance that can be used to build
335335
a set of calls to dispatch."""
336-
# return self.client.batch()
337-
raise NotImplemented
336+
return self.client.batch()
338337

339338

340339
_registries: Dict[str, Registry] = {}
@@ -565,7 +564,11 @@ def add_call(self, call: Call) -> Batch:
565564
self.calls.append(call)
566565
return self
567566

568-
def dispatch(self) -> List[DispatchID]:
567+
def clear(self):
568+
"""Reset the batch."""
569+
self.calls = []
570+
571+
async def dispatch(self) -> List[DispatchID]:
569572
"""Dispatch dispatches the calls asynchronously.
570573
571574
The batch is reset when the calls are dispatched successfully.
@@ -576,10 +579,6 @@ def dispatch(self) -> List[DispatchID]:
576579
"""
577580
if not self.calls:
578581
return []
579-
dispatch_ids = asyncio.run(self.client.dispatch(self.calls))
582+
dispatch_ids = await self.client.dispatch(self.calls)
580583
self.clear()
581584
return dispatch_ids
582-
583-
def clear(self):
584-
"""Reset the batch."""
585-
self.calls = []

0 commit comments

Comments
 (0)