oration
oration copied to clipboard
Async notifications
We have notifications from #62, but we should be able to return the response before sending the email. May need to spawn off a future, or invoke something in the rocket framework I'm currently unaware of.
Maybe futures-awat could be helpful?
Had a chat to the author of Rocket yesterday, he is interested in putting something like this into rocket_contrib
if I get it working.
Notes:
We're looking for a threadsafe queue, something like deque but with a threadsafe worker. Rayon may be using something like this under the hood, but that needs to be verified. With this queue, store a pointer to one side of the queue in Rocket's managed state so it is accessible within handlers and such. The other side of the queues would be given to a thread pool where workers can take tasks from. The endpoint of the queue stored in managed state needs to be Send + Sync
.
Just to add to that, Rayon uses coco, which is now depreciated in favour of crossbeam. There's also a crossbeam-deque which may prove to be a winner.
Hmm... From the crossbeam-deque docs
A
Deque
doesn't implementSync
so it cannot be shared among multiple threads. However, it can createStealer
s, and those can be easily cloned, shared, and sent to other threads.Stealer
s can onlysteal
elements from the top.
chan may actually be a decent candidate.