00:00 So we converted from asyncio to Trio
00:03 and we saw things got simpler this async with block.
00:06 The nursery concept is quite simple.
00:08 Let me show you how we can use that
00:10 for even greater benefit.
00:11 I talked about cancellation. Now watch this.
00:14 Let's suppose we want this to run for either
00:17 five seconds and finish successfully
00:19 or if it goes past five seconds
00:20 we're going to cancel all the work.
00:22 OK, even all the child tasks that maybe
00:24 those processes themselves kicked off.
00:27 How'd we do that? It sounds complicated, right?
00:30 Watch this. With trio.move_on_after, let's say 5.
00:36 How about that? Let's see what happens here.
00:39 It should run for a little bit.
00:40 Do some generating, do some producing, some consuming
00:43 and then it should cancel.
00:45 So this line should print out in just about five seconds.
00:48 Let's find out what happens, it's working, and it's working.
00:52 Five seconds are past, and boom. We ran out of time. We're done.
00:57 We canceled them, straight away. How cool is that?
01:01 So if we make that less work, two, two, and four
01:04 something like that, should be able to produce
01:06 all the work and just finish early.
01:08 No cancellation, 2.42 seconds.
01:11 But if it takes too long, this cancellation
01:13 kicks in and off it goes.
01:15 So these interesting coordination concepts
01:18 like to have this block only run for so long
01:21 with some sort of time out, also if this thing kicks off
01:25 child tasks and then you decide to cancel it or time it out
01:29 or something like that or this one has an error.
01:32 Even those get canceled if they're still running.
01:34 There's really interesting stuff that happens
01:36 around this behind the scenes that does happen
01:39 in normal asyncio, definitely doesn't happen
01:41 in threading or multiprocessing that makes this
01:44 a really nice coordination framework.
01:46 And that's Trio, like I said
01:47 there's actually a lot more to it.
01:49 You can build really interesting things from the ground up.
01:51 But I think this is enough to give you
01:53 some inspiration and some ideas to go explore it
01:55 if it's useful for you.
