Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Applied dart format to code.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutton committed Aug 17, 2024
1 parent bc5bae8 commit fb1ce8f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
6 changes: 3 additions & 3 deletions lib/mailbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class Mailbox {
/// Gets the [Mailbox]'s state which can change concurrently.
/// Once a [Mailbox] has reached the [MailboxState.closed]
/// state it can no longer change state.
MailboxState get state => _mutex.runLocked(()
=> MailboxState.from(_mailbox.ref.state));
MailboxState get state =>
_mutex.runLocked(() => MailboxState.from(_mailbox.ref.state));

bool isEmpty() => state == MailboxState.empty;

Expand Down Expand Up @@ -215,7 +215,7 @@ class Mailbox {
return _emptyResponse;
}

// TODO: remove feature detection once 3.1 becomes stable.
// TODO(Slava.Egorva): remove feature detection once 3.1 becomes stable.
// ignore: omit_local_variable_types
final Uint8List Function(int) asTypedList = buffer.asTypedList;
if (asTypedList is Uint8List Function(int,
Expand Down
4 changes: 2 additions & 2 deletions lib/sendable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// BSD-style license that can be found in the LICENSE file.

abstract final class Sendable<T> {
static Sendable<T> wrap<T, U>(T Function(U) make, U data)
=> _SendableImpl._(make, data);
static Sendable<T> wrap<T, U>(T Function(U) make, U data) =>
_SendableImpl._(make, data);

T materialize();
}
Expand Down
27 changes: 14 additions & 13 deletions test/mailbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ void main() {
expect(await helperResult, equals('success'));
});

Future<String> startHelperIsolateClose(Sendable<Mailbox> sendableMailbox)
// ignore: discarded_futures
=> Isolate.run(() {
sleep(const Duration(milliseconds: 500));
final mailbox = sendableMailbox.materialize();
try {
mailbox.take();
// ignore: avoid_catches_without_on_clauses
} catch (_) {
return 'success';
}
return 'failed';
});
Future<String> startHelperIsolateClose(Sendable<Mailbox> sendableMailbox)
// ignore: discarded_futures
=>
Isolate.run(() {
sleep(const Duration(milliseconds: 500));
final mailbox = sendableMailbox.materialize();
try {
mailbox.take();
// ignore: avoid_catches_without_on_clauses
} catch (_) {
return 'success';
}
return 'failed';
});

test('mailbox close', () async {
final mailbox = Mailbox()
Expand Down
35 changes: 19 additions & 16 deletions test/primitives_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ void main() {
/// Returns success
///
Future<String> spawnHelperIsolate(
// ignore: discarded_futures
int ptrAddress, Sendable<Mutex> sendableMutex) => Isolate.run(() {
int ptrAddress, Sendable<Mutex> sendableMutex) {
// ignore: discarded_futures
return Isolate.run(() {
final ptr = Pointer<Uint8>.fromAddress(ptrAddress);
final mutex = sendableMutex.materialize();

Expand All @@ -51,6 +52,7 @@ void main() {

return 'success';
});
}

test('isolate', () async {
await using((arena) async {
Expand Down Expand Up @@ -105,21 +107,22 @@ void main() {

group('condvar', () {
Future<String> spawnHelperIsolate(
int ptrAddress,
Sendable<Mutex> sendableMutex,
Sendable<ConditionVariable> sendableCondVar) async => Isolate.run(() {
final ptr = Pointer<Uint8>.fromAddress(ptrAddress);
final mutex = sendableMutex.materialize();
final condVar = sendableCondVar.materialize();

return mutex.runLocked(() {
ptr.value = 1;
while (ptr.value == 1) {
condVar.wait(mutex);
}
return ptr.value == 2 ? 'success' : 'failure';
int ptrAddress,
Sendable<Mutex> sendableMutex,
Sendable<ConditionVariable> sendableCondVar) async =>
Isolate.run(() {
final ptr = Pointer<Uint8>.fromAddress(ptrAddress);
final mutex = sendableMutex.materialize();
final condVar = sendableCondVar.materialize();

return mutex.runLocked(() {
ptr.value = 1;
while (ptr.value == 1) {
condVar.wait(mutex);
}
return ptr.value == 2 ? 'success' : 'failure';
});
});
});

test('isolate', () async {
await using((arena) async {
Expand Down

0 comments on commit fb1ce8f

Please sign in to comment.