Skip to content

Commit 5681da8

Browse files
committed
Callbacks and AsyncCallbacks added param support
1 parent dddafe6 commit 5681da8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

shiny/_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ async def __anext__(self):
517517
# ==============================================================================
518518
class Callbacks:
519519
def __init__(self) -> None:
520-
self._callbacks: dict[int, tuple[Callable[[], None], bool]] = {}
520+
self._callbacks: dict[int, tuple[Callable[..., None], bool]] = {}
521521
self._id: int = 0
522522

523523
def register(
524-
self, fn: Callable[[], None], once: bool = False
524+
self, fn: Callable[..., None], once: bool = False
525525
) -> Callable[[], None]:
526526
self._id += 1
527527
id = self._id
@@ -533,14 +533,14 @@ def _():
533533

534534
return _
535535

536-
def invoke(self) -> None:
536+
def invoke(self, *args: Any, **kwargs: Any) -> None:
537537
# The list() wrapper is necessary to force collection of all the items before
538538
# iteration begins. This is necessary because self._callbacks may be mutated
539539
# by callbacks.
540540
for id, value in list(self._callbacks.items()):
541541
fn, once = value
542542
try:
543-
fn()
543+
fn(*args, **kwargs)
544544
finally:
545545
if once:
546546
if id in self._callbacks:
@@ -552,11 +552,11 @@ def count(self) -> int:
552552

553553
class AsyncCallbacks:
554554
def __init__(self) -> None:
555-
self._callbacks: dict[int, tuple[Callable[[], Awaitable[None]], bool]] = {}
555+
self._callbacks: dict[int, tuple[Callable[..., Awaitable[None]], bool]] = {}
556556
self._id: int = 0
557557

558558
def register(
559-
self, fn: Callable[[], Awaitable[None]], once: bool = False
559+
self, fn: Callable[..., Awaitable[None]], once: bool = False
560560
) -> Callable[[], None]:
561561
self._id += 1
562562
id = self._id
@@ -568,14 +568,14 @@ def _():
568568

569569
return _
570570

571-
async def invoke(self) -> None:
571+
async def invoke(self, *args: Any, **kwargs: Any) -> None:
572572
# The list() wrapper is necessary to force collection of all the items before
573573
# iteration begins. This is necessary because self._callbacks may be mutated
574574
# by callbacks.
575575
for id, value in list(self._callbacks.items()):
576576
fn, once = value
577577
try:
578-
await fn()
578+
await fn(*args, **kwargs)
579579
finally:
580580
if once:
581581
if id in self._callbacks:

0 commit comments

Comments
 (0)