Impl Future<Output = JsValue> -> js_sys::Promise

How can I convert a impl Future<Output = JsValue> to a js_sys::Promise ?

The XY problem is as follows:

   pub async fn handle(self: &Rc<Self>, s: &str, v: &JsValue) -> JsValue { todo!() }

We want to create a function of type signature:

    pub fn handle_sync(self: &Rc<Self>, s: &str, v: &JsValue) -> js_sys::Promise {
      let x = self.handle(s, v);
      ??? how do we convert x to a js_sys::Promise ???

This only needs to work on target=wasm32-unknown-unknown

Basically I have an async Rust function. I want to wrap it in such a way so we can pass it as a callback to JS function.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.