1 00:00:06,750 --> 00:00:08,580 - Our next basic pattern here is 2 00:00:08,580 --> 00:00:09,630 wait for result. 3 00:00:09,630 --> 00:00:12,510 It is the opposite of wait for task. 4 00:00:12,510 --> 00:00:15,380 We're gonna use this pattern in things like 5 00:00:15,380 --> 00:00:18,150 drop patterns and fan-out patterns. 6 00:00:18,150 --> 00:00:19,883 Let's walk through this again. 7 00:00:20,970 --> 00:00:22,550 We're gonna go again use that idea of 8 00:00:22,550 --> 00:00:24,410 a manager and employer where the manager ... 9 00:00:24,410 --> 00:00:25,570 We're gonna hire some employee. 10 00:00:25,570 --> 00:00:28,690 But we start on line 53, and again we see 11 00:00:28,690 --> 00:00:30,220 the un-buffered channel. 12 00:00:30,220 --> 00:00:34,680 Again, what I see is signaling with guarantees 13 00:00:34,680 --> 00:00:36,130 and signaling with data. 14 00:00:36,130 --> 00:00:38,540 We want guarantees and we're gonna 15 00:00:38,540 --> 00:00:40,720 signal with string data. 16 00:00:40,720 --> 00:00:42,360 This time, we go to launch. 17 00:00:42,360 --> 00:00:44,370 Here we are; we're a manager. 18 00:00:44,370 --> 00:00:45,230 There we are. 19 00:00:45,230 --> 00:00:47,350 We're starting our path of execution 20 00:00:47,350 --> 00:00:48,460 on our own core. 21 00:00:48,460 --> 00:00:50,610 Then we go off again and we start 22 00:00:50,610 --> 00:00:53,010 the employee path of execution. 23 00:00:53,010 --> 00:00:54,680 That's what you see on line 56 24 00:00:54,680 --> 00:00:57,350 with the literal function call and the keyword go. 25 00:00:57,350 --> 00:01:00,050 But this time the employee already knows 26 00:01:00,050 --> 00:01:01,490 what they're supposed to do. 27 00:01:01,490 --> 00:01:02,810 They don't have to wait for us. 28 00:01:02,810 --> 00:01:04,900 We're gonna be able to reduce some latency here 29 00:01:04,900 --> 00:01:08,310 because the employer already knows the task at hand. 30 00:01:08,310 --> 00:01:11,180 That employee begins to do their work. 31 00:01:11,180 --> 00:01:13,210 They're doing the work immediately. 32 00:01:13,210 --> 00:01:15,680 The question is, how long does it take 33 00:01:15,680 --> 00:01:16,970 to do this work? 34 00:01:16,970 --> 00:01:19,920 The reality is, is that the time it takes 35 00:01:19,920 --> 00:01:22,740 to do this is unknown. 36 00:01:22,740 --> 00:01:25,350 The time it takes to do this is unknown. 37 00:01:25,350 --> 00:01:27,350 While that employee's doing their work, 38 00:01:27,350 --> 00:01:29,130 we continue to move down 39 00:01:29,130 --> 00:01:32,360 and we get to line 62. 40 00:01:32,360 --> 00:01:36,570 Line 62 means that we are now blocked again. 41 00:01:36,570 --> 00:01:39,540 That is the channel receive. 42 00:01:39,540 --> 00:01:40,500 We're blocked. 43 00:01:40,500 --> 00:01:43,010 There it is, the unary channel operation. 44 00:01:43,010 --> 00:01:44,060 What we're really doing is waiting for 45 00:01:44,060 --> 00:01:46,620 this employee to finish so we can get on. 46 00:01:46,620 --> 00:01:49,430 We are now blocked right here. 47 00:01:49,430 --> 00:01:52,080 We're blocked right here on the receive. 48 00:01:52,080 --> 00:01:54,760 The question is, how long are we gonna be blocked for? 49 00:01:54,760 --> 00:01:57,240 Again, that is unknown. 50 00:01:57,240 --> 00:01:58,800 It's unknown; we don't know how long 51 00:01:58,800 --> 00:02:01,230 that work is going to take. 52 00:02:01,230 --> 00:02:03,250 Eventually, what happens here? 53 00:02:03,250 --> 00:02:05,400 Eventually what happens is the work gets done. 54 00:02:05,400 --> 00:02:07,670 The work gets done, and then on line 58, 55 00:02:07,670 --> 00:02:10,440 the employee signals with data, 56 00:02:10,440 --> 00:02:11,820 the data being maybe a piece of paper, 57 00:02:11,820 --> 00:02:14,440 the result, back to us. 58 00:02:14,440 --> 00:02:18,670 Remember now, we're in this channel receive here. 59 00:02:18,670 --> 00:02:20,740 We're blocked, we're blocked. 60 00:02:20,740 --> 00:02:22,040 We're in a channel receive. 61 00:02:22,040 --> 00:02:24,073 We're waiting for this data. 62 00:02:25,150 --> 00:02:26,920 We can do it this way since I'm on this side. 63 00:02:26,920 --> 00:02:28,810 We're in that unary operation. 64 00:02:28,810 --> 00:02:31,650 We're in that channel receive right here. 65 00:02:31,650 --> 00:02:35,110 Now what happens is this is gonna be the send. 66 00:02:35,110 --> 00:02:37,410 We've got the send here now coming in. 67 00:02:37,410 --> 00:02:39,870 We were already in the receive. 68 00:02:39,870 --> 00:02:41,420 The receive was waiting. 69 00:02:41,420 --> 00:02:43,640 There it is; we have the send. 70 00:02:43,640 --> 00:02:46,540 Now we've got the send and the receive 71 00:02:46,540 --> 00:02:49,220 coming together again. 72 00:02:49,220 --> 00:02:51,210 Again, the send is on line 58, 73 00:02:51,210 --> 00:02:53,770 the receive is on line 62. 74 00:02:53,770 --> 00:02:56,120 The receive came in place first. 75 00:02:56,120 --> 00:02:58,110 We're waiting, the work gets done. 76 00:02:58,110 --> 00:03:00,513 Line 58, the send comes in. 77 00:03:03,190 --> 00:03:05,790 We have a guarantee that the send happens 78 00:03:05,790 --> 00:03:08,470 because the receive happens first on line 62, 79 00:03:08,470 --> 00:03:11,840 which means that we get to move first. 80 00:03:11,840 --> 00:03:14,513 We come in and we get to move first, 81 00:03:15,350 --> 00:03:18,250 nanoseconds before the send finishes. 82 00:03:18,250 --> 00:03:19,270 We have our data. 83 00:03:19,270 --> 00:03:21,530 And then this employee knows. 84 00:03:21,530 --> 00:03:23,830 This is the second; it gets to move next. 85 00:03:23,830 --> 00:03:25,950 The employee knows that we've received a result. 86 00:03:25,950 --> 00:03:27,830 There's guarantee; there's no way I can 87 00:03:27,830 --> 00:03:29,500 throw the employee under the bus 88 00:03:29,500 --> 00:03:31,400 because we have guarantees that the send 89 00:03:31,400 --> 00:03:33,760 happens before the receive. 90 00:03:33,760 --> 00:03:36,900 Again, we're coming in, we're blocked on the receive. 91 00:03:36,900 --> 00:03:38,570 Some unknown amount of time it takes 92 00:03:38,570 --> 00:03:39,403 to get the work done. 93 00:03:39,403 --> 00:03:41,210 We don't know how long we're gonna be waiting. 94 00:03:41,210 --> 00:03:42,520 Then finally the work is done. 95 00:03:42,520 --> 00:03:44,580 The send and the receive come together. 96 00:03:44,580 --> 00:03:47,200 The receive happens first, the send happens next. 97 00:03:47,200 --> 00:03:48,900 Nanoseconds, but whatever. 98 00:03:48,900 --> 00:03:50,170 We can't lose those print statements 99 00:03:50,170 --> 00:03:51,100 to look at order. 100 00:03:51,100 --> 00:03:53,930 And then we're able to move on. 101 00:03:53,930 --> 00:03:55,000 Wait for result. 102 00:03:55,000 --> 00:03:56,464 We're gonna use this again for 103 00:03:56,464 --> 00:03:59,110 drop patterns and fan-out patterns. 104 00:03:59,110 --> 00:03:59,943 This is gonna be another 105 00:03:59,943 --> 00:04:03,270 very powerful base pattern. 106 00:04:03,270 --> 00:04:05,360 These are two of the really core patterns 107 00:04:05,360 --> 00:04:08,360 we just looked at; wait for task and wait for result. 108 00:04:08,360 --> 00:04:11,230 The next core pattern is gonna be ideas around 109 00:04:11,230 --> 00:04:14,060 signaling without data, where we're gonna really 110 00:04:14,060 --> 00:04:16,700 use those around cancellation and deadlines. 111 00:04:16,700 --> 00:04:19,143 We're gonna call that wait for finished.