jhugman / uniffi-bindgen-react-native

A uniffi bindings generator for calling Rust from react-native
https://jhugman.github.io/uniffi-bindgen-react-native/
Other
50 stars 5 forks source link

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

Closed jhugman closed 2 months ago

jhugman commented 3 months 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