Skip to content

Commit

Permalink
refresh snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwindmill committed Jan 4, 2024
1 parent a43eca4 commit 508c6ae
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Worker {
));
};

// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand Down
8 changes: 4 additions & 4 deletions examples/concurrency/lib/robust_ports_example/spawn_1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Worker {
final ReceivePort _responses;

static Future<Worker> spawn() async {
// Create a receive port and add it's initial message handler
// Create a receive port and add its initial message handler.
final initPort = RawReceivePort();
final connection = Completer<(ReceivePort, SendPort)>.sync();
initPort.handler = (initialMessage) {
Expand All @@ -26,12 +26,12 @@ class Worker {
// #enddocregion

Future<Object?> parseJson(String message) async {
// TODO: ensure the port is still open
// TODO: Ensure the port is still open.
_commands.send(message);
}

Worker._(this._commands, this._responses) {
// TODO: initialize main isolate receive port listener
// TODO: Initialize main isolate receive port listener.
}

void _handleResponsesFromIsolate(dynamic message) {
Expand All @@ -43,6 +43,6 @@ class Worker {
}

static void _startRemoteIsolate(SendPort sp) {
// TODO: Initialize worker isolate's ports
// TODO: Initialize worker isolate's ports.
}
}
10 changes: 5 additions & 5 deletions examples/concurrency/lib/robust_ports_example/spawn_2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Worker {
final ReceivePort _responses;

static Future<Worker> spawn() async {
// Create a receive port and add it's initial message handler
// Create a receive port and add its initial message handler
final initPort = RawReceivePort();
final connection = Completer<(ReceivePort, SendPort)>.sync();
initPort.handler = (initialMessage) {
Expand All @@ -19,7 +19,7 @@ class Worker {
commandPort,
));
};
// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand All @@ -35,12 +35,12 @@ class Worker {
// #enddocregion

Future<Object?> parseJson(String message) async {
// TODO: ensure the port is still open
// TODO: Ensure the port is still open.
_commands.send(message);
}

Worker._(this._commands, this._responses) {
// TODO: initialize main isolate receive port listener
// TODO: Initialize main isolate receive port listener.
}

void _handleResponsesFromIsolate(dynamic message) {
Expand All @@ -52,6 +52,6 @@ class Worker {
}

static void _startRemoteIsolate(SendPort sp) {
// TODO: Initialize worker isolate's ports
// TODO: Initialize worker isolate's ports.
}
}
8 changes: 4 additions & 4 deletions examples/concurrency/lib/robust_ports_example/start.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class Worker {
final ReceivePort _responses;

Future<Object?> parseJson(String message) async {
// TODO: ensure the port is still open
// TODO: Ensure the port is still open.
_commands.send(message);
}

static Future<Worker> spawn() async {
// TODO: Add functionality to create a new Worker object with a
// connection to a spawned isolate
// connection to a spawned isolate.
throw UnimplementedError();
}

Worker._(this._commands, this._responses) {
// TODO: initialize main isolate receive port listener
// TODO: Initialize main isolate receive port listener.
}

void _handleResponsesFromIsolate(dynamic message) {
Expand All @@ -31,7 +31,7 @@ class Worker {
}

static void _startRemoteIsolate(SendPort sp) {
// TODO: Initialize worker isolate's ports
// TODO: Initialize worker isolate's ports.
}
}
// #enddocregion
2 changes: 1 addition & 1 deletion examples/concurrency/lib/robust_ports_example/step_4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Worker {
commandPort,
));
};
// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Worker {
commandPort,
));
};
// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Worker {
commandPort,
));
};
// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand Down Expand Up @@ -70,7 +70,7 @@ class Worker {
SendPort sendPort,
) {
receivePort.listen((message) {
// New if-block
// New if-block.
if (message == 'shutdown') {
receivePort.close();
return;
Expand Down
22 changes: 11 additions & 11 deletions src/language/isolates.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ To handle this, use a [`Completer`][].
- First, add a class-level property called a `Completer` and name
it `_isolateReady`.
- Next, add a call to `complete()` on the completer in
the `_handleResponsesFromIsolate` method (created in step 4) if the message is
the `_handleResponsesFromIsolate` method (created in [step 4](#step-4-handle-messages-on-the-main-isolate)) if the message is
a `SendPort`.
- Finally, in the `parseJson` method, add `await _isolateReady.future` before
adding `_sendPort.send`. This ensures that no message can be sent to the
Expand Down Expand Up @@ -549,18 +549,18 @@ class Worker {
final ReceivePort _responses;
Future<Object?> parseJson(String message) async {
// TODO: ensure the port is still open
// TODO: Ensure the port is still open.
_commands.send(message);
}
static Future<Worker> spawn() async {
// TODO: Add functionality to create a new Worker object with a
// connection to a spawned isolate
// connection to a spawned isolate.
throw UnimplementedError();
}
Worker._(this._commands, this._responses) {
// TODO: initialize main isolate receive port listener
// TODO: Initialize main isolate receive port listener.
}
void _handleResponsesFromIsolate(dynamic message) {
Expand All @@ -572,7 +572,7 @@ class Worker {
}
static void _startRemoteIsolate(SendPort sp) {
// TODO: Initialize worker isolate's ports
// TODO: Initialize worker isolate's ports.
}
}
```
Expand Down Expand Up @@ -618,7 +618,7 @@ class Worker {
final ReceivePort _responses;
static Future<Worker> spawn() async {
// Create a receive port and add it's initial message handler
// Create a receive port and add its initial message handler.
final initPort = RawReceivePort();
final connection = Completer<(ReceivePort, SendPort)>.sync();
initPort.handler = (initialMessage) {
Expand All @@ -643,7 +643,7 @@ logic that handles receiving messages after setting up communication is
complete. This benefit will become more obvious as the logic in the other
methods grows.

#### Step 3: Spawn a worker isolate with `Isolate.spawn`.
#### Step 3: Spawn a worker isolate with `Isolate.spawn`

This step continues to fill in the `Worker.spawn` method. You’ll add the code
needed to spawn an isolate, and return an instance of `Worker` from this class.
Expand All @@ -667,7 +667,7 @@ class Worker {
final ReceivePort _responses;
static Future<Worker> spawn() async {
// Create a receive port and add it's initial message handler
// Create a receive port and add its initial message handler
final initPort = RawReceivePort();
final connection = Completer<(ReceivePort, SendPort)>.sync();
initPort.handler = (initialMessage) {
Expand All @@ -677,7 +677,7 @@ class Worker {
commandPort,
));
};
// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand Down Expand Up @@ -943,7 +943,7 @@ static void _handleCommandsToIsolate(
SendPort sendPort,
) {
receivePort.listen((message) {
// New if-block
// New if-block.
if (message == 'shutdown') {
receivePort.close();
return;
Expand Down Expand Up @@ -1023,7 +1023,7 @@ class Worker {
));
};
// Spawn the isolate
// Spawn the isolate.
try {
await Isolate.spawn(_startRemoteIsolate, (initPort.sendPort));
} on Object {
Expand Down

0 comments on commit 508c6ae

Please sign in to comment.