From the course: Rust: Asynchronous Programming with Tokio

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Barrier example

Barrier example

- [Instructor] For our soda company example, we'll be using a barrier and notify to partition the soda can task into batches of 12. All right, let's start with the imports. Use standard library, sync arc. use tokio, sync barrier. Barrier wait result, and notify. Use tokio time sleep and duration. For the barrier function, we need to pass in the barrier notify, and then return a barrier wait result. So let's do that, and let's call this function barrier example. Barrier example, passing in a barrier, arc, barrier, notify, arc notify, and then returning a barrier result. So the main purpose of the barrier example is to have the barrier. So let's set that up. Let wait result equals to barrier. Wait dot await. And then let's print out what the task are going to be doing. Print line waiting, waiting at barrier. And then afterwards, print line pass through the barrier. Barrier wait results are special.…

Contents