- Our next basic pattern here is
wait for result.
It is the opposite of wait for task.
We're gonna use this pattern in things like
drop patterns and fan-out patterns.
Let's walk through this again.
We're gonna go again use that idea of
a manager and employer where the manager ...
We're gonna hire some employee.
But we start on line 53, and again we see
the un-buffered channel.
Again, what I see is signaling with guarantees
and signaling with data.
We want guarantees and we're gonna
signal with string data.
This time, we go to launch.
Here we are; we're a manager.
There we are.
We're starting our path of execution
on our own core.
Then we go off again and we start
the employee path of execution.
That's what you see on line 56
with the literal function call and the keyword go.
But this time the employee already knows
what they're supposed to do.
They don't have to wait for us.
We're gonna be able to reduce some latency here
because the employer already knows the task at hand.
That employee begins to do their work.
They're doing the work immediately.
The question is, how long does it take
to do this work?
The reality is, is that the time it takes
to do this is unknown.
The time it takes to do this is unknown.
While that employee's doing their work,
we continue to move down
and we get to line 62.
Line 62 means that we are now blocked again.
That is the channel receive.
We're blocked.
There it is, the unary channel operation.
What we're really doing is waiting for
this employee to finish so we can get on.
We are now blocked right here.
We're blocked right here on the receive.
The question is, how long are we gonna be blocked for?
Again, that is unknown.
It's unknown; we don't know how long
that work is going to take.
Eventually, what happens here?
Eventually what happens is the work gets done.
The work gets done, and then on line 58,
the employee signals with data,
the data being maybe a piece of paper,
the result, back to us.
Remember now, we're in this channel receive here.
We're blocked, we're blocked.
We're in a channel receive.
We're waiting for this data.
We can do it this way since I'm on this side.
We're in that unary operation.
We're in that channel receive right here.
Now what happens is this is gonna be the send.
We've got the send here now coming in.
We were already in the receive.
The receive was waiting.
There it is; we have the send.
Now we've got the send and the receive
coming together again.
Again, the send is on line 58,
the receive is on line 62.
The receive came in place first.
We're waiting, the work gets done.
Line 58, the send comes in.
We have a guarantee that the send happens
because the receive happens first on line 62,
which means that we get to move first.
We come in and we get to move first,
nanoseconds before the send finishes.
We have our data.
And then this employee knows.
This is the second; it gets to move next.
The employee knows that we've received a result.
There's guarantee; there's no way I can
throw the employee under the bus
because we have guarantees that the send
happens before the receive.
Again, we're coming in, we're blocked on the receive.
Some unknown amount of time it takes
to get the work done.
We don't know how long we're gonna be waiting.
Then finally the work is done.
The send and the receive come together.
The receive happens first, the send happens next.
Nanoseconds, but whatever.
We can't lose those print statements
to look at order.
And then we're able to move on.
Wait for result.
We're gonna use this again for
drop patterns and fan-out patterns.
This is gonna be another
very powerful base pattern.
These are two of the really core patterns
we just looked at; wait for task and wait for result.
The next core pattern is gonna be ideas around
signaling without data, where we're gonna really
use those around cancellation and deadlines.
We're gonna call that wait for finished.