jhugman / uniffi-bindgen-react-native

A uniffi bindings generator for calling Rust from react-native
Other
0 stars 0 forks source link

AbortController: Add task cancellation to Rust to request cancellation to Typescript #74

Open jhugman opened 3 weeks ago

jhugman commented 3 weeks ago

Speaking to @zzorba and @bdk: the concept of cancellation in both Rust and Javascript/Typescript is similar: it is really a request for cancellation, which the task co-operatively decides to respect or not.

For generated code, Rust is going to send a request to Javascript. In Javascript an AbortController maintains a signal. If we make a new AbortController for each async callback method call, and pass the callback signal, this might be a) unobtrusive for the callbacks that doesn't want to offer the task cancellation b) available to those that do.

Proof of concept that typescript methods can accept optional parameters.

Playground Link