diff options
Diffstat (limited to 'patches')
| -rw-r--r-- | patches/patches/085_async.patch | 6 | ||||
| -rw-r--r-- | patches/patches/086_async2.patch | 10 | ||||
| -rw-r--r-- | patches/patches/087_async3.patch | 19 | ||||
| -rw-r--r-- | patches/patches/088_async4.patch | 6 | ||||
| -rw-r--r-- | patches/patches/089_async5.patch | 8 | ||||
| -rw-r--r-- | patches/patches/090_async6.patch | 8 | ||||
| -rw-r--r-- | patches/patches/093_async9.patch | 14 | ||||
| -rw-r--r-- | patches/patches/094_async10.patch | 8 | ||||
| -rw-r--r-- | patches/patches/095_quiz_async.patch | 52 |
9 files changed, 64 insertions, 67 deletions
diff --git a/patches/patches/085_async.patch b/patches/patches/085_async.patch index ca8b102..108eae1 100644 --- a/patches/patches/085_async.patch +++ b/patches/patches/085_async.patch @@ -1,6 +1,6 @@ ---- exercises/085_async.zig 2026-04-01 20:40:08.904999609 +0200 -+++ answers/085_async.zig 2026-04-01 20:40:05.641933231 +0200 -@@ -37,7 +37,7 @@ +--- exercises/085_async.zig 2026-04-04 16:01:01.509555724 +0200 ++++ answers/085_async.zig 2026-04-04 16:00:58.541495688 +0200 +@@ -38,7 +38,7 @@ const std = @import("std"); pub fn main(init: std.process.Init) !void { diff --git a/patches/patches/086_async2.patch b/patches/patches/086_async2.patch index 9a672a6..1738089 100644 --- a/patches/patches/086_async2.patch +++ b/patches/patches/086_async2.patch @@ -1,11 +1,11 @@ ---- exercises/086_async2.zig 2026-04-03 19:42:15.274532915 +0200 -+++ answers/086_async2.zig 2026-04-03 21:30:18.180019206 +0200 -@@ -38,7 +38,7 @@ +--- exercises/086_async2.zig 2026-04-05 12:41:11.350626443 +0200 ++++ answers/086_async2.zig 2026-04-05 12:42:00.879791167 +0200 +@@ -44,7 +44,7 @@ // Now collect the result. What method on Future gives us - // the value, blocking if it isn't ready yet? + // the value, blocking until it's ready? - const answer = future.???(io); + const answer = future.await(io); - std.debug.print("The answer is: {}\n", .{answer}); + print("The answer is: {}\n", .{answer}); } diff --git a/patches/patches/087_async3.patch b/patches/patches/087_async3.patch index 8365e7a..91ba9af 100644 --- a/patches/patches/087_async3.patch +++ b/patches/patches/087_async3.patch @@ -1,18 +1,11 @@ ---- exercises/087_async3.zig 2026-04-01 22:51:05.540094851 +0200 -+++ answers/087_async3.zig 2026-04-01 22:50:44.579669189 +0200 -@@ -29,12 +29,12 @@ - const io = init.io; - +--- exercises/087_async3.zig 2026-04-05 16:12:48.317265515 +0200 ++++ answers/087_async3.zig 2026-04-05 16:12:52.269343030 +0200 +@@ -28,7 +28,7 @@ // Launch both tasks asynchronously. -- var future_a = io.async(slowAdd, .{ 10, 20 }); + var future_a = io.async(slowAdd, .{ 1, 2 }); + defer _ = future_a.cancel(io); - var future_b = ???(slowMul, .{ 6, 7 }); -+ var future_a = io.async(slowAdd, .{ 1, 2 }); + var future_b = io.async(slowMul, .{ 6, 7 }); + defer _ = future_b.cancel(io); // Await both results. - const sum = future_a.await(io); -- const product = future_b.???(io); -+ const product = future_b.await(io); - - print("{} + {} = {}\n", .{ 1, 2, sum }); - print("{} * {} = {}\n", .{ 6, 7, product }); diff --git a/patches/patches/088_async4.patch b/patches/patches/088_async4.patch index 1faf30e..6cf549f 100644 --- a/patches/patches/088_async4.patch +++ b/patches/patches/088_async4.patch @@ -1,10 +1,10 @@ ---- exercises/088_async4.zig 2026-04-01 23:17:31.066443941 +0200 -+++ answers/088_async4.zig 2026-04-01 23:17:39.251612131 +0200 +--- exercises/088_async4.zig 2026-04-06 12:22:06.643385622 +0200 ++++ answers/088_async4.zig 2026-04-06 12:22:11.820491035 +0200 @@ -38,7 +38,7 @@ // Wait for all tasks to finish. // What Group method blocks until all tasks complete? -- try group.??? +- try group.???(io); + try group.await(io); print("All tasks finished!\n", .{}); diff --git a/patches/patches/089_async5.patch b/patches/patches/089_async5.patch index d2baa96..3cea4e9 100644 --- a/patches/patches/089_async5.patch +++ b/patches/patches/089_async5.patch @@ -1,10 +1,10 @@ ---- exercises/089_async5.zig 2026-04-01 23:40:40.505855238 +0200 -+++ answers/089_async5.zig 2026-04-01 23:40:10.176236971 +0200 -@@ -40,7 +40,7 @@ +--- exercises/089_async5.zig 2026-04-06 14:38:54.443726849 +0200 ++++ answers/089_async5.zig 2026-04-06 14:38:39.945438309 +0200 +@@ -46,7 +46,7 @@ // We don't want to wait 10 seconds! // Which Future method requests cancellation AND returns the result? -- const result = ???; +- const result = future.???(io); + const result = future.cancel(io); print("Task returned: {}\n", .{result}); diff --git a/patches/patches/090_async6.patch b/patches/patches/090_async6.patch index 5ac777b..6289708 100644 --- a/patches/patches/090_async6.patch +++ b/patches/patches/090_async6.patch @@ -1,10 +1,10 @@ ---- exercises/090_async6.zig 2026-04-02 10:25:34.016616118 +0200 -+++ answers/090_async6.zig 2026-04-02 10:27:48.827144051 +0200 -@@ -47,7 +47,7 @@ +--- exercises/090_async6.zig 2026-04-06 18:49:37.232023422 +0200 ++++ answers/090_async6.zig 2026-04-06 18:49:22.189720687 +0200 +@@ -52,7 +52,7 @@ // Wait for the first finisher. // What Select method returns the first completed result? -- const winner = ???; +- const winner = try sel.???(); + const winner = try sel.await(); switch (winner) { diff --git a/patches/patches/093_async9.patch b/patches/patches/093_async9.patch index f759921..ebdfce2 100644 --- a/patches/patches/093_async9.patch +++ b/patches/patches/093_async9.patch @@ -1,11 +1,11 @@ ---- exercises/093_async9.zig 2026-04-03 13:44:50.526780809 +0200 -+++ answers/093_async9.zig 2026-04-03 13:44:54.957870294 +0200 -@@ -36,7 +36,7 @@ - // Launch with a guaranteed separate thread. - // Which Io method guarantees true concurrency? +--- exercises/093_async9.zig 2026-04-06 19:26:11.388025362 +0200 ++++ answers/093_async9.zig 2026-04-06 19:18:36.242931688 +0200 +@@ -43,7 +43,7 @@ + // Launch with a guaranteed separate unit of concurrency. + // Which Io method guarantees this? // (Hint: unlike io.async, this one can fail!) - var future = try io.???(compute, .{io}); + var future = try io.concurrent(compute, .{io}); + defer _ = future.cancel(io); - print("Main thread continues...\n", .{}); - + // Note: All breaks in this excercise (using sleep) diff --git a/patches/patches/094_async10.patch b/patches/patches/094_async10.patch index ae0d26d..e721485 100644 --- a/patches/patches/094_async10.patch +++ b/patches/patches/094_async10.patch @@ -1,10 +1,10 @@ ---- exercises/094_async10.zig 2026-04-03 14:25:16.600025924 +0200 -+++ answers/094_async10.zig 2026-04-03 14:24:56.192615893 +0200 -@@ -50,8 +50,8 @@ +--- exercises/094_async10.zig 2026-04-06 19:36:59.873966580 +0200 ++++ answers/094_async10.zig 2026-04-06 19:37:12.416216872 +0200 +@@ -51,8 +51,8 @@ // Protect this section from cancellation. // What method swaps the cancel protection state? -- const old = io.???(. blocked); +- const old = io.???(.blocked); - defer _ = io.???(old); + const old = io.swapCancelProtection(.blocked); + defer _ = io.swapCancelProtection(old); diff --git a/patches/patches/095_quiz_async.patch b/patches/patches/095_quiz_async.patch index dbaae07..e3d2a79 100644 --- a/patches/patches/095_quiz_async.patch +++ b/patches/patches/095_quiz_async.patch @@ -1,38 +1,42 @@ ---- exercises/095_quiz_async.zig 2026-04-03 18:04:53.577391455 +0200 -+++ answers/095_quiz_async.zig 2026-04-03 18:05:42.570392172 +0200 +--- exercises/095_quiz_async.zig 2026-04-06 19:55:17.111817364 +0200 ++++ answers/095_quiz_async.zig 2026-04-06 19:56:16.063974543 +0200 @@ -51,7 +51,7 @@ + fn addReading(self: *GardenWeather, io: std.Io, reading: Reading) void { // Bug 1: The collector needs to lock before modifying // shared state. What Mutex method acquires the lock? - self.mutex.lock(io) catch return; - self.mutex.???(io) catch return; -+ defer self.mutex.unlock(io); ++ self.mutex.lock(io) catch return; + defer self.mutex.unlock(io); switch (reading.sensor_type) { - .thermometer => self.temperature = reading.value, -@@ -79,9 +79,9 @@ - // Bug 2: io.async doesn't guarantee a separate thread. - // Which Io method guarantees true concurrency? - // (Don't forget: it can fail, so you need 'try'!) -- try sensors.???(io, sensor, .{ io, &queue, .thermometer, 20 }); -- try sensors.???(io, sensor, .{ io, &queue, .hygrometer, 60 }); -- try sensors.???(io, sensor, .{ io, &queue, .anemometer, 10 }); -+ try sensors.concurrent(io, sensor, .{ io, &queue, .thermometer, 20 }); -+ try sensors.concurrent(io, sensor, .{ io, &queue, .hygrometer, 60 }); -+ try sensors.concurrent(io, sensor, .{ io, &queue, .anemometer, 10 }); +@@ -78,7 +78,7 @@ + // Bug 2: The collector needs guaranteed concurrency. + // What method ensures a separate unit of concurrency? + // (Don't forget: it can fail!) +- var collector_future = try io.???(collector, .{ io, &queue, &weather }); ++ var collector_future = try io.concurrent(collector, .{ io, &queue, &weather }); + defer _ = collector_future.cancel(io); + + // Sensor group: the sensors can use async — they just need +@@ -91,7 +91,7 @@ - // Collector group: processes readings from the queue. - var collectors: std.Io.Group = .init; -@@ -90,7 +90,6 @@ // Bug 3: Wait for ALL sensors to finish sending their readings. // What Group method blocks until all tasks complete? - try sensors.await(io); -- // try sensors.???(io); +- try sensors.???(io); ++ try sensors.await(io); // All sensors done — close the queue so the collector knows // there's no more data coming. -@@ -104,8 +103,8 @@ +@@ -99,15 +99,14 @@ + + // Wait for the collector to drain the remaining queue. + _ = collector_future.await(io); +- // _ = collector_future.???(io); + + // Now write the garden report. This is critical — it must + // NOT be interrupted, even if something tries to cancel us! // - // Bug 4: Protect this section from cancellation. + // Bug 5: Protect this section from cancellation. // What Io method swaps the cancel protection state? - const old_protection = io.???(.blocked); - defer _ = io.???(old_protection); @@ -41,9 +45,9 @@ printGardenReport(&weather); } -@@ -127,7 +126,7 @@ +@@ -129,7 +128,7 @@ - // Bug 5: Send the reading into the queue. + // Bug 6: Send the reading into the queue. // What Queue method sends a single element? - queue.???(io, reading) catch return; + queue.putOne(io, reading) catch return; |
