extendr / extendr.github.io

https://extendr.github.io/
MIT License
5 stars 3 forks source link

Using tokio for parallelism & async #20

Open JosiahParry opened 4 months ago

JosiahParry commented 4 months ago

This section covers how to utilize async functions with tokio.

Example use case: calling an API endpoint to get many requests in parallel.

Structure:

  1. Define a response struct with serde
  2. Create an async function to query the endpoint using async reqwest
  3. Wrapper function to spawn many tasks in parallel second example (https://docs.rs/tokio/latest/tokio/task/fn.spawn.html#examples?)
  4. create an extendr function with a runtime to evaluate the async function in a blocking context.

This can be taught in a progressive manner as individual sections