holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
410 stars 69 forks source link

Add support for async and generator functions in rx.pipe #924

Closed philippjfr closed 3 months ago

philippjfr commented 3 months ago

We already support using asynchronous and generator functions as inputs to a reactive expression but until now we did not handle them when you use them as an input to an operation that is performed on the data. This meant that .rx.pipe and .rx.map would simply return the coroutine or generator as the value instead of evaluating it lazily.

Here we add support for these by scheduling the task on the event loop and then triggering an event when the function evaluates. Internally this is achieved by creating a Trigger which is added as one of the dependencies of the reactive expression such as that any consumer of the expression (whether Panel, the display hook or anything else) is notified when the async function or generator yields a new value.

In testing this I also found an oversight which meant that if you used a bound function as the input to .rx.pipe it would not extract its dependencies.