Channel, passing results

Question

How to interact with the “Waker” pattern?

Blocking

Execution of “normal Rust code” blocks. It blocks until data is returned, and continues with the obtained data.

Diagram 1: “Polling in a loop” blocks.

Nonblocking

Execution of the “Waker” pattern does not block.

Diagram 2: Wakers put code execution in nonblocking mode.

The question, again

How to interact with the “Waker” pattern, as the code execution is nonblocking?

Answer

Solution 1: blocks the current thread until data is obtained

Parks the current thread, runs wakers and futures in dedicated threads, and unpark the suspended thread when data is ready.

Solution 2: interacts with data using the “channel” mechanism

“Channel” is a communication mechanism, allowing data to be sent and received across threads. The mechanism can often work in both blocking and nonblocking modes.

Using the “channel” mechanism, data can be sent across threads when it’s ready and obtained, and will be received in a specific thread, where the data processing starts.