Skip to content

Commit

Permalink
Merge pull request 'fibers' (dart-lang#12) from fibers into main
Browse files Browse the repository at this point in the history
  • Loading branch information
antonbashir committed Sep 9, 2024
2 parents 7a39b2b + c54f272 commit 6b3313e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 35 deletions.
2 changes: 1 addition & 1 deletion sdk/lib/isolate/isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final class Isolate {
///
/// Some control messages require a specific capability to be passed along
/// with the message (see [pauseCapability] and [terminateCapability]),
/// otherwise the message is ignored by the isolate.
/// otherwise the message is ignored by the isolate.ц
final SendPort controlPort;

/// Capability granting the ability to pause the isolate.
Expand Down
32 changes: 18 additions & 14 deletions tests/lib/fiber/fiber_exceptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ void main() {
_run(mainException: true);
_run(childException: true);
_run(childException: true, mainCatchChild: true);
_run(mainYield: true);
_run(mainYield: true, mainCatchChild: true);
_run(childYield: true);
_run(childYield: true, mainCatchChild: true);
}
Expand All @@ -28,12 +26,16 @@ void _run({mainException = false, childException = false, mainCatchChild = false
name: "child");
if (mainCatchChild) {
final main = Fiber.main(
entry: () => Expect.equals(
Expect.throws<FiberException>(() {
Fiber.spawn(child);
Fiber.suspend();
}).message,
"child"));
entry: () => Expect.equals(
Expect.throws<FiberException>(
() {
Fiber.spawn(child);
Fiber.suspend();
},
).message,
"child",
),
);
main.start();
return;
}
Expand All @@ -48,12 +50,14 @@ void _run({mainException = false, childException = false, mainCatchChild = false
final child = Fiber.child(entry: () => Fiber.suspend(), name: "child");
if (mainCatchChild) {
final main = Fiber.main(
entry: () => Expect.equals(
Expect.throws<FiberException>(() {
Fiber.spawn(child);
throw FiberException("main");
}).message,
"main"));
entry: () => Expect.equals(
Expect.throws<FiberException>(() {
Fiber.spawn(child);
throw FiberException("main");
}).message,
"main",
),
);
main.start();
return;
}
Expand Down
74 changes: 54 additions & 20 deletions tests/lib/fiber/fiber_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,63 @@ var commonState = "";
void main() {
mainFiber.start();
var variable = "variable";
Fiber.main(entry: () {
Expect.equals("variable", variable);
variable = "after fiber";
}).start();
Fiber.main(
entry: () {
Expect.equals("variable", variable);
variable = "after fiber";
},
).start();
Expect.equals("after fiber", variable);
variable = "variable";
Fiber.main(entry: () {
Expect.equals("variable", variable);
variable = "after main fiber";
Fiber.spawn(Fiber.child(
entry: () {
Expect.equals("after main fiber", variable);
variable = "after child fiber";
Fiber.suspend();
Expect.equals("after child fiber after main fiber", variable);
variable = "finish";
},
name: "child"));
Expect.equals("after child fiber", variable);
variable = "after child fiber after main fiber";
Fiber.suspend();
}).start();
Fiber.main(
entry: () {
Expect.equals("variable", variable);
variable = "after main fiber";
Fiber.spawn(
Fiber.child(
entry: () {
Expect.equals("after main fiber", variable);
variable = "after child fiber";
Fiber.suspend();
Expect.equals("after child fiber after main fiber", variable);
variable = "finish";
},
name: "child",
),
);
Expect.equals("after child fiber", variable);
variable = "after child fiber after main fiber";
Fiber.suspend();
},
).start();
Expect.equals("finish", variable);

variable = "level 1";
Fiber.main(
entry: () {
Expect.equals("level 1", variable);
variable = "level 2";
Fiber.spawn(
Fiber.child(
entry: () {
Expect.equals("level 2", variable);
variable = "level 3";
Fiber.spawn(
Fiber.child(
name: "child",
entry: () {
Expect.equals("level 3", variable);
variable = "level 4";
},
),
);
},
name: "child",
),
);
},
).start();
Expect.equals("level 4", variable);
}

void mainEntry() {
Expand Down

0 comments on commit 6b3313e

Please sign in to comment.