15- Waiting for the First Task
Jul 04, 2026 01:19
· 2:13
· English
· Whisper Turbo
· 2 Enregistraments
@ info: status
0:03
S…
Speaker 2 (15- Waiting for the First Task)
Let's say there are two ways to get the current weather in a given city.
0:06
S…
Speaker 2 (15- Waiting for the First Task)
Perhaps we have two different remote services,
0:09
S…
Speaker 2 (15- Waiting for the First Task)
but sometimes one of these services responds a little bit slower.
0:13
S…
Speaker 2 (15- Waiting for the First Task)
So we want to call these services concurrently and as soon as we get a response,
0:17
S…
Speaker 2 (15- Waiting for the First Task)
we're going to display it to the user.
0:19
S…
Speaker 2 (15- Waiting for the First Task)
Let me show you how to do that.
0:20
S…
Speaker 2 (15- Waiting for the First Task)
So I'm going to create two completable futures.
0:23
S…
Speaker 2 (15- Waiting for the First Task)
Here's the first one completable future that supply async.
0:28
S…
Speaker 2 (15- Waiting for the First Task)
Let's say this is our slow link.
0:31
S…
Speaker 1 (15- Waiting for the First Task)
So
0:32
S…
Speaker 2 (15- Waiting for the First Task)
in the body of this lambda,
0:34
S…
Speaker 2 (15- Waiting for the First Task)
I'm going to call long task that simulate and
0:38
S…
Speaker 2 (15- Waiting for the First Task)
then return 20.
0:39
S…
Speaker 2 (15- Waiting for the First Task)
That is the current weather,
0:40
S…
Speaker 2 (15- Waiting for the First Task)
let's say in New York City.
0:42
S…
Speaker 2 (15- Waiting for the First Task)
Now we create a second task completable
0:46
S…
Speaker 2 (15- Waiting for the First Task)
future that supply async.
0:48
S…
Speaker 2 (15- Waiting for the First Task)
Now this simulates a fast link.
0:50
S…
Speaker 2 (15- Waiting for the First Task)
So here we return 20 immediately.
0:53
S…
Speaker 2 (15- Waiting for the First Task)
Now we're going to call both these services concurrently.
0:56
S…
Speaker 2 (15- Waiting for the First Task)
And as soon as one of them respond,
0:58
S…
Speaker 2 (15- Waiting for the First Task)
we're going to print the result on the terminal.
1:00
S…
Speaker 1 (15- Waiting for the First Task)
So
1:02
S…
Speaker 2 (15- Waiting for the First Task)
Here we call completable future dot in the last
1:06
S…
Speaker 2 (15- Waiting for the First Task)
video you learned about all of with this we can wait for the completion of all tasks.
1:10
S…
Speaker 2 (15- Waiting for the First Task)
We have another method called any of this returns
1:14
S…
Speaker 2 (15- Waiting for the First Task)
a new completable future that will complete as soon as one of these
1:18
S…
Speaker 2 (15- Waiting for the First Task)
completable futures that we pass here completes.
1:21
S…
Speaker 2 (15- Waiting for the First Task)
So just like before we have var arcs here we
1:25
S…
Speaker 2 (15- Waiting for the First Task)
can pass any number of completable futures.
1:27
S…
Speaker 2 (15- Waiting for the First Task)
I'm going to pass first and second.
1:30
S…
Speaker 2 (15- Waiting for the First Task)
This will give us a new completable future.
1:33
S…
Speaker 2 (15- Waiting for the First Task)
Let's store it in this variable fastest.
1:37
S…
Speaker 2 (15- Waiting for the First Task)
Look at the type of this variable.
1:38
S…
Speaker 2 (15- Waiting for the First Task)
It's a completable future of object.
1:41
S…
Speaker 1 (15- Waiting for the First Task)
Now,
1:43
S…
Speaker 2 (15- Waiting for the First Task)
right after we get the result,
1:45
S…
Speaker 2 (15- Waiting for the First Task)
we can call then accept.
1:48
S…
Speaker 2 (15- Waiting for the First Task)
We're going to consume the result.
1:50
S…
Speaker 2 (15- Waiting for the First Task)
So we get the temperature and print it on a terminal.
1:54
S…
Speaker 1 (15- Waiting for the First Task)
Now,
1:57
S…
Speaker 2 (15- Waiting for the First Task)
let's reformat our code.
1:59
S…
Speaker 2 (15- Waiting for the First Task)
That is better.
2:00
S…
Speaker 1 (15- Waiting for the First Task)
So,
2:01
S…
Speaker 2 (15- Waiting for the First Task)
run.
2:03
S…
Speaker 2 (15- Waiting for the First Task)
See, we got the result immediately.
2:06
S…
Speaker 2 (15- Waiting for the First Task)
We didn't have to wait three seconds to get the current weather from our slow service.
@ info Politica IA
Resumit
@ action: button
Resumit...
Demandar a l'IA sus aquesta transcripcion
Demandatz quicòm sus aquesta transcripcion - l'IA trobarà las seccions pertinentas e respondrà.