I am trying to understand how to construct and return an instance of Box<Future<String>>
from a function, where the future is completed explicitly later on triggered by an external event. Essentially, I am looking at the rust analogy for Promise in Scala. Is the such a thing? How should I construct it in rust?
Pseudo code:
let saved_global_promise = Promise<String>::new(); // this what I would do in scala, but it does not exist in Rust
fn promise_me_now() -> Box<Future<String>> {
return saved_global_promise.future;
}
fn complete_promise_later_explicitly() {
promise.complete("some result text"); // activates poll for the previously returned future to complete
}