Skip to content

Commit

Permalink
Close #185 and close #16: send busy/idle when an Effect is executing …
Browse files Browse the repository at this point in the history
…and output binding progress when an Output is recalculating
  • Loading branch information
cpsievert committed Jun 8, 2022
1 parent fff04e9 commit fd551fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 4 additions & 0 deletions shiny/reactive/_reactives.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ def on_invalidate_cb() -> None:

def _continue() -> None:
ctx.add_pending_flush(self._priority)
if self._session:
_utils.run_coro_sync(self._session._send_message({"busy": "busy"}))

if self._suspended:
self._on_resume = _continue
Expand All @@ -483,6 +485,8 @@ def _continue() -> None:
async def on_flush_cb() -> None:
if not self._destroyed:
await self._run()
if self._session:
await self._session._send_message({"busy": "idle"})

ctx.on_invalidate(on_invalidate_cb)
ctx.on_flush(on_flush_cb)
Expand Down
5 changes: 5 additions & 0 deletions shiny/session/_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ def _send_remove_ui(self, selector: str, multiple: bool) -> None:
msg = {"selector": selector, "multiple": multiple}
_utils.run_coro_sync(self._send_message({"shiny-remove-ui": msg}))

def _send_progress(self, type: str, message: object) -> None:
msg: Dict[str, object] = {"progress": {"type": type, "message": message}}
_utils.run_coro_sync(self._send_message(msg))

@add_example()
async def send_custom_message(self, type: str, message: Dict[str, object]) -> None:
"""
Expand Down Expand Up @@ -822,6 +826,7 @@ async def output_obs():
await self._session._send_message(
{"recalculating": {"name": fn_name, "status": "recalculating"}}
)
self._session._send_progress("binding", {"id": fn_name})

message: Dict[str, object] = {}
try:
Expand Down
19 changes: 7 additions & 12 deletions shiny/ui/_progress.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
__all__ = ("Progress",)

from types import TracebackType
from typing import Optional, Dict, Any, Type
from typing import Optional, Type
from warnings import warn

from .._docstring import add_example
from .._utils import run_coro_sync, rand_hex
from .._utils import rand_hex
from ..session import Session, require_active_session


Expand Down Expand Up @@ -40,7 +40,7 @@ def __init__(
self._session = require_active_session(session)

msg = {"id": self._id, "style": self._style}
self._send_progress("open", msg)
self._session._send_progress("open", msg)

def __enter__(self) -> "Progress":
return self
Expand Down Expand Up @@ -97,7 +97,9 @@ def set(
"style": self._style,
}

self._send_progress("update", {k: v for k, v in msg.items() if v is not None})
self._session._send_progress(
"update", {k: v for k, v in msg.items() if v is not None}
)

def inc(
self,
Expand Down Expand Up @@ -150,12 +152,5 @@ def close(self) -> None:
warn("Attempting to close progress, but progress already closed.")
return None

self._send_progress("close", {"id": self._id, "style": self._style})
self._session._send_progress("close", {"id": self._id, "style": self._style})
self._closed = True

def _send_progress(self, type: str, message: Dict[str, Any]) -> None:
run_coro_sync(
self._session._send_message(
{"progress": {"type": type, "message": message}}
)
)

0 comments on commit fd551fe

Please sign in to comment.