@alice,
Thanks for responding...
I'll have to try to recreate it...
I've trashed a lot of approaches...
It will take a little bit...
Most of the walls were related to not being able to spawn_blocking on a future...
I tried a lot of ways to wrap it the ways I know how, but no dice...
in abscissa::tokio
pub fn run<A, F>(app: &'static AppCell<A>, future: F) -> Result<F::Output, FrameworkError>
where
A: Application,
F: Future,
{
take_runtime(app).map(|mut runtime| runtime.block_on(future))
}
I've tried to create variations of this one
(This is just to illustrate, not close to working or compiling)
pub fn spawn_blocking<A, C>(app: &'static AppCell<A>, closure: C) -> ()
where
A: Application,
C: FnOnce() +Send+ 'static,
{
take_runtime(app).map(|mut runtime| async {
let join_handle =
runtime.handle().spawn_blocking(closure);
let _ = join_handle.await;
});
}
It failed with various issues around lifetime and send
I tried it from the other end
// current "operational"
let _join_handle =
std::thread::Builder::new().name("abscissaMain".to_owned()).spawn(move || {
// abscissa_core::Application::run(&APPLICATION, args);
//info!("{} service starting", config::SVC_NAME);
info!("{} service starting alt_boot(&APPLICATION, [{:?}])", config::SVC_NAME, args);
alt_boot(&APPLICATION, args);
}
);
Which creates the RT and starts the the whole show.
I created a new runtime and spawned_blocking()...
But I could not pass the runtime into spawned thread.
I tried to get the handle, set the rt, then spawn...
borrow checked complained.
The transition of control from abscissa to my app happens:
(Which calls the runner up top)
impl Runnable for AgentCmd {
/// Start the application.
fn run(&self) {
let _ = abscissa_tokio::run(&APPLICATION,
async{
let (cmd, mut todo_list, tgt_srvr) =
match self.get_cmd(&mut app_writer())
{
Ok(vals) => vals,
Err(err) => {
error!("Initialization failed: {:?}", err);
return;
},
};
if todo_list.len() < 1 {
error!("Nothing to do, exiting");
return;
}
let upload_interval =
Duration::from_secs(cmd.upload_interval.unwrap_or(60));
info!("[v:{}], Starting agent Loop Verbose={}", env!("CARGO_PKG_VERSION"), self.verbose);
loop {
APPLICATION.read().get_handler_controller().read()
.handle_tasks_until(&mut todo_list, upload_interval).await;
if !cmd.dump_data(&mut todo_list, &tgt_srvr) {
info!("AgentCmd: No user, not updating until new user logged in");
let mut interval = tokio::time::interval(Duration::from_secs(60));
{ interval.tick().await;}
}
}
}
);
}
}
I changed it to call abscissa_tokio::spawn_blocking instead of abscissa_tokio::run...
Which is where the problem of passing self blocked me...
The best solution, from my standpoint, would be to have:
tokio::await_future<F:Future>(future: F) -> F::Output
that would handle the transitions...
What do you think the likelihood of that is ?
Again, I really appreciate the insight...
I love rust... but it can be... let's say "challenging" at times.
JR