src/content/docs/tutorials/counter-async-app/full-async-actions.md
Now that we have introduced Events and Actions, we are going introduce a new mpsc::channel for
Actions. The advantage of this is that we can programmatically trigger updates to the state of the
app by sending Actions on the channel.
Here's the run function refactored from before to introduce an Action channel. In addition to
refactoring, we store the action_tx half of the channel in the App.
{{#include @code/tutorials/ratatui-counter-async-app/src/main.rs:run}}
Running the code with this change should give the exact same behavior as before.
Now that we have stored the action_tx half of the channel in the App, we can use this to
schedule tasks. For example, let's say we wanted to press J and K to perform some network
request and then increment the counter.
First, we have to update my Action enum:
{{#include @code/tutorials/ratatui-counter-async-app/src/main.rs:action_enum}}
Next, we can update my event handler:
{{#include @code/tutorials/ratatui-counter-async-app/src/main.rs:get_action}}
Finally, we can handle the action in my update function by spawning a tokio task:
{{#include @code/tutorials/ratatui-counter-async-app/src/main.rs:update}}
Here is the full code for reference:
{{#include @code/tutorials/ratatui-counter-async-app/src/main.rs:all}}
With that, we have a fully async application that is tokio ready to spawn tasks to do work concurrently.