mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-25 17:49:58 -04:00
Inspired by the changes in #1013 I was thinking about the use case for `sync_*` and how we handle error cases. Most notably while we give the callback the option to stop the loop, we don't really give an indication to the outside, how to interpret that cancellation: was there a failure? should we restart? Take e.g. a connectivity issue on the wire, we'd constantly loop and just `warn`, what you might or might not see. Even if you handle that in the `sync_with_result_callback` and thus break the loop, the outer caller now still doesn't know whether everything is honky dory or whether they should restart. This Changes reworks that area by having all the `sync` return `Result<(), Error>`, where `()` means it was ended by the inner callback (which in `sync()` never occurs) or `Error` is the error either the inner `result_callback` found or the that was coming from the `send` in the first place. Thus allowing us to e.g. back down to sync as it was a dead wire or restart it if there was only a temporary problem. Making all that a just a bit more "rust-y".
Example usage of matrix-rust-sdk from WASM
This example is a version of the command bot that runs as WASM in your browser instead of natively on your machine.
To run this example, first ensure:
- The wasm-unknown-unknown target is available:
rustup target add wasm32-unknown-unknown. wasm-packis in the path: see instructions here.- A homeserver is available at
http://localhost:8008with a userusernameand passwordwordpass. If this is not the case, you'll want to update these connection settings insrc/lib.rsbefore building.
You can then build the example locally with:
npm install
npm run serve
and then visiting http://localhost:8080 in a browser should run the example!
This example is loosely based off of
this example,
an example usage of fetch from wasm-bindgen.
NOTE: The webpage at http://localhost:8080 will not display anything. It just
runs the bot on the page, printing log messages to the console and responding to
the !party command.