sciter-sdk / pysciter

Python bindings for Sciter
https://sciter.com
MIT License
398 stars 40 forks source link

How to asynchronously call native function? #51

Open GirkovArpa opened 3 years ago

GirkovArpa commented 3 years ago

How to accomplish the same as the below using Python instead of Rust?


Rust

fn sum_async(&self, x: i32, y: i32, callback: Value) -> () {
    thread::spawn(move || {
        callback.call(None, &make_args!(x + y), None).unwrap();
    });
}

JavaScript

function sum_async(a, b) {
  return new Promise((resolve) => {
    Window.this.xcall('sum_async', a, b, resolve);
  });
}
pravic commented 3 years ago

Exactly the same: https://docs.python.org/3/library/threading.html

Also there's https://docs.python.org/3/library/asyncio.html