Skip to content

Local invocations with registered functions #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resonate/resonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def lfi[**P, R](
**kwargs: P.kwargs,
) -> LFI[R]:
opts = Options(version=self._registry.latest(func))
return LFI(Local(self._next(), self._cid, self._id, opts), func, args, kwargs, opts)
return LFI(Local(self._next(), self._cid, self._id, opts), func.func if isinstance(func, Function) else func, args, kwargs, opts)

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

@overload
def rfi[**P, R](
Expand Down
13 changes: 13 additions & 0 deletions tests/test_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ def resonate_instance(store: Store, message_source: MessageSource) -> Generator[
time.sleep(3)


def test_local_invocations_with_registered_functions(resonate_instance: Resonate) -> None:
@resonate_instance.register
def recursive(ctx: Context, n: int) -> Generator[Yieldable, Any, int]:
if n == 1:
return 1
elif n % 2 == 0:
return (yield ctx.lfc(recursive, n - 1))
else:
return (yield (yield ctx.lfi(recursive, n - 1)))

assert recursive.run("recursive", 5).result() == 1


@pytest.mark.parametrize("durable", [True, False])
def test_fail_inmediatelly_fn(resonate_instance: Resonate, durable: bool) -> None:
with pytest.raises(RuntimeError):
Expand Down
Loading