Skip to content
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

Concurrent rendering naming fixes #1211

Merged
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
8 changes: 4 additions & 4 deletions docs/source/about/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ Unreleased

**Added**

- :pull:`1165` - Allow concurrent renders of discrete component tree - enable this
experimental feature by setting `REACTPY_ASYNC_RENDERING=true`. This should improve
the overall responsiveness of your app, particularly when handling larger renders
that would otherwise block faster renders from being processed.
- :pull:`1165` - Allow concurrently rendering discrete component trees - enable this
experimental feature by setting `REACTPY_ASYNC_RENDERING=true`. This improves
the overall responsiveness of your app in situations where larger renders would
otherwise block smaller renders from executing.

**Changed**

Expand Down
4 changes: 2 additions & 2 deletions src/py/reactpy/reactpy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ def boolean(value: str | bool | int) -> bool:
"""A default timeout for testing utilities in ReactPy"""

REACTPY_ASYNC_RENDERING = Option(
"REACTPY_CONCURRENT_RENDERING",
"REACTPY_ASYNC_RENDERING",
default=False,
mutable=True,
validator=boolean,
)
"""Whether to render components concurrently. This is currently an experimental feature."""
"""Whether to render components asynchronously. This is currently an experimental feature."""
8 changes: 5 additions & 3 deletions src/py/reactpy/reactpy/core/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async def deliver(self, event: LayoutEventMessage) -> None:

async def render(self) -> LayoutUpdateMessage:
if REACTPY_ASYNC_RENDERING.current:
return await self._concurrent_render()
return await self._parallel_render()
else: # nocov
return await self._serial_render()

Expand All @@ -147,8 +147,10 @@ async def _serial_render(self) -> LayoutUpdateMessage: # nocov
else:
return await self._create_layout_update(model_state)

async def _concurrent_render(self) -> LayoutUpdateMessage:
"""Await the next available render. This will block until a component is updated"""
async def _parallel_render(self) -> LayoutUpdateMessage:
"""Await to fetch the first completed render within our asyncio task group.
We use the `asyncio.tasks.wait` API in order to return the first completed task.
"""
await self._render_tasks_ready.acquire()
done, _ = await wait(self._render_tasks, return_when=FIRST_COMPLETED)
update_task: Task[LayoutUpdateMessage] = done.pop()
Expand Down
8 changes: 4 additions & 4 deletions src/py/reactpy/tests/test_core/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@


@pytest.fixture(autouse=True, params=[True, False])
def concurrent_rendering(request):
def async_rendering(request):
with patch.object(REACTPY_ASYNC_RENDERING, "current", request.param):
yield request.param

Expand Down Expand Up @@ -1252,9 +1252,9 @@ def App():
assert c["attributes"]["color"] == "blue"


async def test_concurrent_renders(concurrent_rendering):
if not concurrent_rendering:
raise pytest.skip("Concurrent rendering not enabled")
async def test_async_renders(async_rendering):
if not async_rendering:
raise pytest.skip("Async rendering not enabled")

child_1_hook = HookCatcher()
child_2_hook = HookCatcher()
Expand Down
Loading