trunk icon indicating copy to clipboard operation
trunk copied to clipboard

Promise in `inline_js`

Open fredfortier opened this issue 5 years ago • 2 comments

I realize that this is wasm_bindgen question, but I'm interested in the value of a Promise after it resolves.

#[wasm_bindgen(inline_js = "export function load_my_account() {\
    window.account.load().then(result => sendMeToYew);
    return true; \
 }")]
extern "C" {
    fn load_my_account() -> bool;
}

Is there a simple way to do this? Using a callback to the yew App perhaps?

fredfortier avatar Oct 24 '20 07:10 fredfortier

Hey there @fredfortier. There are a few different ways to handle this. None of them really have anything to do with Trunk however haha :). No worries either way.

The pattern I would probably choose would be pass a callback into that JS function which can be called once the promise resolves on the JS side. There are definitely other patterns, some better than others depending on the use case.

Keep me posted! Hopefully Trunk is offering some usefulness in your project. Cheers

thedodd avatar Oct 30 '20 00:10 thedodd

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Dec 08 '23 00:12 github-actions[bot]