-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
Implement support for reactive generator functions #5019
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5019 +/- ##
===========================================
+ Coverage 73.40% 83.57% +10.17%
===========================================
Files 271 271
Lines 38361 38586 +225
===========================================
+ Hits 28157 32247 +4090
+ Misses 10204 6339 -3865
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 59 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
The streaming example is extremely powerful. The Async and Classic generators too. ❤️ The downside is that we have to teach our users |
Questions
|
Other use cases for generator functionsI added another use case for generator functions in Panel that I believe should be supported as well. Please consider this in the context of this PR. Thanks. #5020 |
It runs once but if you
Absolutely, it works just like a regular function with
Absolutely, this should be significantly more lightweight than periodic callbacks, here's 100 instances of the streaming generator |
Okay, feature-wise this is now done. Last item was implementing synchronization primitives to ensure the async generators were updated when a dependency changes, e.g. we make the timeout dynamic: import asyncio
import panel as pn
import random
pn.extension()
timeout = pn.widgets.FloatSlider(start=0.1, end=1.0, value=1, name='Timeout')
@pn.depends(timeout)
async def stream(timeout):
while True:
await asyncio.sleep(timeout)
yield random.randint(0, 100)
pn.Column(
timeout,
pn.FlexBox(*(pn.indicators.Number(value=stream, name='Random', font_size='12pt') for _ in range(200)))
).servable() |
6ee112a
to
089f664
Compare
In looking at #5016 I realized that the only way to write reactive expressions with multiple steps in a natural way would be using generators. So I had a go at implementing support for them and now I'm in love, here's a simplified version of the app in #5016:
Asynchronous Generator
Classic Generator
Streaming example