Skip to content

Commit 3864cf4

Browse files
authored
Local invocations with registered functions (#262)
1 parent f3106f9 commit 3864cf4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

resonate/resonate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def lfi[**P, R](
306306
**kwargs: P.kwargs,
307307
) -> LFI[R]:
308308
opts = Options(version=self._registry.latest(func))
309-
return LFI(Local(self._next(), self._cid, self._id, opts), func, args, kwargs, opts)
309+
return LFI(Local(self._next(), self._cid, self._id, opts), func.func if isinstance(func, Function) else func, args, kwargs, opts)
310310

311311
def lfc[**P, R](
312312
self,
@@ -315,7 +315,7 @@ def lfc[**P, R](
315315
**kwargs: P.kwargs,
316316
) -> LFC[R]:
317317
opts = Options(version=self._registry.latest(func))
318-
return LFC(Local(self._next(), self._cid, self._id, opts), func, args, kwargs, opts)
318+
return LFC(Local(self._next(), self._cid, self._id, opts), func.func if isinstance(func, Function) else func, args, kwargs, opts)
319319

320320
@overload
321321
def rfi[**P, R](

tests/test_bridge.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ def resonate_instance(store: Store, message_source: MessageSource) -> Generator[
224224
time.sleep(3)
225225

226226

227+
def test_local_invocations_with_registered_functions(resonate_instance: Resonate) -> None:
228+
@resonate_instance.register
229+
def recursive(ctx: Context, n: int) -> Generator[Yieldable, Any, int]:
230+
if n == 1:
231+
return 1
232+
elif n % 2 == 0:
233+
return (yield ctx.lfc(recursive, n - 1))
234+
else:
235+
return (yield (yield ctx.lfi(recursive, n - 1)))
236+
237+
assert recursive.run("recursive", 5).result() == 1
238+
239+
227240
@pytest.mark.parametrize("durable", [True, False])
228241
def test_fail_inmediatelly_fn(resonate_instance: Resonate, durable: bool) -> None:
229242
with pytest.raises(RuntimeError):

0 commit comments

Comments
 (0)