-
-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Is your feature request related to a problem? Please describe.
I want to combine bastion with winit for a desktop application that uses wgpu rendering to display content.
For this, we want to have a thread dedicated to wgpu (at least the main render loop, it might spawn more children for specific tasks). It should be able to receive and send messages via bastion to other parts of the application (like the UI). This thread might own local data that is not Send
.
Describe the solution you'd like
For the function passed to children.with_exec
, I tried the following code:
async fn exec(ctx: BastionContext) -> Result<(), ()> {
let task = blocking! {
run!(async move {
loop {
msg! { ctx.recv().await?,
msg: Message => { /* … */ };
// …
}
}
Ok(())
})
};
task.await.unwrap()
}
In theory, this should spawn a new task on a thread designated for blocking tasks that then executes ctx.recv()
in a loop without ever switching thread.
However, what actually happens is that ctx.recv().await
never returns, it just hangs there.
You can see the full example here.
Describe alternatives you've considered
@o0Ignition0o suggested wrapping the task in the code above in a run!
instead of awaiting it, which does work. However, then I'm blocking a thread that isn't supposed to be blocked, specifically the one calling the exec function.
Alternatively, @o0Ignition0o suggested adding a feature to bastion like create_named
, which specifically spawns an OS thread just for this one async closure. This is what this ticket is about.
I'm currently trying to use tokio's functionality to achieve this, but it's hard to find a way to wrap a non-Send
Future so that I can .await
it in the calling function without blocking that thread.