Created
February 7, 2024 03:59
-
-
Save huntc/152e63e5d8fa8a180435ed0aafc77577 to your computer and use it in GitHub Desktop.
An example of creating a channel for sending commands to self.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (self_commands, mut self_commands_receiver) = mpsc::unbounded_channel(); | |
let (entity_manager_task, commands) = entity_manager::task( | |
Behavior { | |
self_commands, | |
}, | |
file_log_topic_adapter, | |
MAX_COMMANDS, | |
MAX_ENTITIES, | |
); | |
let task_commands = commands.clone().downgrade(); | |
let self_commands_forwarder_task = async move { | |
while let Some(message) = self_commands_receiver.recv().await { | |
if let Some(task_commands) = task_commands.upgrade() { | |
let _ = task_commands.send(message).await; | |
} | |
} | |
}; | |
let handle = | |
tokio::spawn(async { tokio::join!(entity_manager_task, self_commands_forwarder_task).0 }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment