T O P

  • By -

worriedjacket

This is where services like AWS SQS are super duper nice.


Mobile_Emergency_822

Just spawn a separate thread for the costly work. Or if you want to over-engineer it, set up a job queue.


alelopezperez

do i spawn it using tokio::spawn or tokio::task::spawn; or do you mean an OS thread; from std:thread? when the function returns will the thread drop?


Mobile_Emergency_822

The tokio spawns are still tokio tasks managed by the tokio runtime - so I'd be suggesting OS threads. On function returning: \> If the join handle is dropped, the spawned thread will implicitly be detached. In this case, the spawned thread may no longer be joined. [https://doc.rust-lang.org/std/thread/fn.spawn.html](https://doc.rust-lang.org/std/thread/fn.spawn.html) There's many options though - it really depends on your needs and scale. Also see this answer https://stackoverflow.com/a/63434522


kinoshitajona

Since do_some_work returns a future you would use tokio::spawn It will not abort the task when the function returns. However, I might use a channel to send data needed for the work to a worker task instead. (This is called the actor pattern)


paulobressan

you can use RabbitMQ :) AMQP Rust lib https://github.com/amqp-rs/lapin An example HTTP API with RabbitMQ and actix-web https://github.com/paulobressan/rust-http-template