ttytm / webview

V binding for webview - a tiny cross-platform library to build modern cross-platform GUI applications.
https://ttytm.github.io/webview/
MIT License
56 stars 1 forks source link

Time-consuming functions will block application responsiveness. #14

Closed xiusin closed 1 year ago

xiusin commented 1 year ago

vue

   window.get_big_index().then((data) => {
                    state.data = data
   })

vlang

// block
fn get_big_index(event_id &char, raw_args &char, mut app App) {
        mut data := app.api.big_index() or { return }
    app.w.result(event_id, .value, json.encode(data))
}

// no block, but the frontend also won't receive the response data.
fn get_big_index(event_id &char, raw_args &char, mut app App) {
    spawn fn [mut app, event_id] () {
        mut data := app.api.big_index() or { return }

        app.w.result(event_id, .value, json.encode(data))
    }()
}
xiusin commented 1 year ago

I'm sorry for posting a garbage question. After reviewing the cases, I realized that it was my own fault.

ttytm commented 1 year ago

No worries.

I am glad you found a solution :+1: .