Skip to content

Commit

Permalink
multi-threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
dgodinez-dh committed Jan 27, 2025
1 parent a2b5c3f commit d36aa56
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/ui/docs/add-interactivity/queueing-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ This is similar to a waiter taking an order at a restaurant. A waiter does not g

This lets you update multiple state variables—even from multiple components—without triggering too many re-renders. But this also means that the UI will not be updated until after your event handler, and any code in it, completes. This behavior, also known as batching, makes your `deephaven.ui` app run much faster. It also avoids dealing with confusing “half-finished” renders where only some of the variables have been updated.

Note that in multi-threaded cases, state updates are not batched by default. You can use the [use_render_queue](../hooks/use_render_queue.md) to ensure they do get batched if you are going to do work from a background thread. See [`batch-updates`](../hooks/use_render_queue.md#batch-updates) for more information.

## Update the same state multiple times before the next render

If you would like to update the same state variable multiple times before the next render, instead of passing the next state value like `set_number(number + 1)`, you can pass a function that calculates the next state based on the previous one in the queue, like `set_number(lambda n: n + 1)`. It is a way to tell `deephaven.ui` to “do something with the state value” instead of just replacing it.
Expand Down

0 comments on commit d36aa56

Please sign in to comment.