From e2cc339478f980756435f3c3f966851822800016 Mon Sep 17 00:00:00 2001 From: Serious-senpai <57554044+Serious-senpai@users.noreply.github.com> Date: Sat, 14 Sep 2024 09:19:31 +0700 Subject: [PATCH] Replace `var`s with `final`s --- example/example.dart | 4 ++-- lib/src/event.dart | 6 +++--- lib/src/lock.dart | 6 +++--- lib/src/semaphore.dart | 6 +++--- lib/src/types.dart | 2 +- test/event_test.dart | 10 +++++----- test/lock_test.dart | 10 +++++----- test/semaphore_test.dart | 14 +++++++------- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/example/example.dart b/example/example.dart index 7ed6f78..e4e08e5 100644 --- a/example/example.dart +++ b/example/example.dart @@ -18,13 +18,13 @@ class Program { await Future.wait([runFuture(1), runFuture(2), runFuture(3), runFuture(4)]); // Read and print file content to stdout - var content = await file.readAsString(); + final content = await file.readAsString(); print(content); } } void main() async { - var program = Program(); + final program = Program(); // Write header to example file await program.file.writeAsString("EXAMPLE FILE\n"); diff --git a/lib/src/event.dart b/lib/src/event.dart index eac0b71..ccf838f 100644 --- a/lib/src/event.dart +++ b/lib/src/event.dart @@ -28,7 +28,7 @@ class Event { if (_flag) return; _flag = true; - for (var waiter in _waiters) { + for (final waiter in _waiters) { if (!waiter.isCompleted) waiter.complete(); } @@ -43,7 +43,7 @@ class Event { Future wait() async { if (_flag) return; - var waiter = _FutureWaiter(); + final waiter = _FutureWaiter(); _waiters.add(waiter); return waiter.future; @@ -52,7 +52,7 @@ class Event { /// Cancel all futures waiting for this [Event] to be set (those that are waiting for [wait] /// to return). This function throws an [EventCancelledException] to all these futures. void cancelAll() { - for (var waiter in _waiters) { + for (final waiter in _waiters) { waiter.completeError(EventCancelledException()); } diff --git a/lib/src/lock.dart b/lib/src/lock.dart index e5cfb97..e5ef435 100644 --- a/lib/src/lock.dart +++ b/lib/src/lock.dart @@ -51,7 +51,7 @@ class Lock extends _Acquirable { return; } - var waiter = _FutureWaiter(); + final waiter = _FutureWaiter(); _waiters.add(waiter); return waiter.future; @@ -64,7 +64,7 @@ class Lock extends _Acquirable { if (_waiters.isEmpty) { _locked = false; } else { - var waiter = _getNextWaiter(); + final waiter = _getNextWaiter(); waiter.complete(); } } @@ -84,7 +84,7 @@ class Lock extends _Acquirable { /// [LockAcquireFailureException] to them. void cancelAll() { while (_waiters.isNotEmpty) { - var waiter = _waiters.removeFirst(); + final waiter = _waiters.removeFirst(); waiter.completeError(LockAcquireFailureException()); } } diff --git a/lib/src/semaphore.dart b/lib/src/semaphore.dart index 04fc164..5cdc6f9 100644 --- a/lib/src/semaphore.dart +++ b/lib/src/semaphore.dart @@ -26,7 +26,7 @@ abstract class _Semaphore extends _Acquirable { return; } - var waiter = _FutureWaiter(); + final waiter = _FutureWaiter(); _waiters.add(waiter); return waiter.future; @@ -38,7 +38,7 @@ abstract class _Semaphore extends _Acquirable { if (_waiters.isEmpty) { _value++; } else { - var waiter = _getNextWaiter(); + final waiter = _getNextWaiter(); waiter.complete(); } } @@ -57,7 +57,7 @@ abstract class _Semaphore extends _Acquirable { /// [SemaphoreAcquireFailureException] to them. void cancelAll() { while (_waiters.isNotEmpty) { - var waiter = _waiters.removeFirst(); + final waiter = _waiters.removeFirst(); waiter.completeError(SemaphoreAcquireFailureException()); } } diff --git a/lib/src/types.dart b/lib/src/types.dart index 6364f4e..a1ee59d 100644 --- a/lib/src/types.dart +++ b/lib/src/types.dart @@ -9,7 +9,7 @@ abstract class _Acquirable { Future run(Future Function() func) async { await acquire(); try { - var result = await func(); + final result = await func(); return result; } finally { release(); diff --git a/test/event_test.dart b/test/event_test.dart index 140c4be..4d64bab 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -22,15 +22,15 @@ Future mainFuture() async { void main() { test( - "Testing control flow: $event", + "Control flow test: $event", () async { - var futures = >[]; + final futures = >[]; for (int i = 0; i < futures_count; i++) { futures.add(sampleFuture()); } futures.add(mainFuture()); - var timer = Stopwatch(); + final timer = Stopwatch(); timer.start(); await Future.wait(futures); timer.stop(); @@ -42,11 +42,11 @@ void main() { ); test( - "Test event waiting cancellation: $event", + "Event waiting cancellation test: $event", () async { event.clear(); - var futures = >[]; + final futures = >[]; for (int i = 0; i < futures_count; i++) { futures.add(sampleFuture()); } diff --git a/test/lock_test.dart b/test/lock_test.dart index d20f6c0..7fe608f 100644 --- a/test/lock_test.dart +++ b/test/lock_test.dart @@ -11,15 +11,15 @@ void main() { final lock = Lock(); test( - "Testing control flow: $lock", + "Control flow test: $lock", () async { - var futures = >[]; + final futures = >[]; for (int i = 0; i < futures_count; i++) { futures.add(lock.run(() => Future.delayed(waiting))); } futures.add(Future.delayed(short_waiting)); - var timer = Stopwatch(); + final timer = Stopwatch(); timer.start(); await Future.wait(futures); timer.stop(); @@ -31,9 +31,9 @@ void main() { ); test( - "Test lock acquire cancellation: $lock", + "Lock acquisition cancellation test: $lock", () async { - var futures = >[]; + final futures = >[]; for (int i = 0; i < futures_count; i++) { futures.add(lock.run(() => Future.delayed(waiting))); } diff --git a/test/semaphore_test.dart b/test/semaphore_test.dart index 05cb131..74c4160 100644 --- a/test/semaphore_test.dart +++ b/test/semaphore_test.dart @@ -10,16 +10,16 @@ const concurrency = 4; void main() { final semaphores = [Semaphore(concurrency), BoundedSemaphore(concurrency)]; - for (var semaphore in semaphores) { + for (final semaphore in semaphores) { test( - "Testing control flow: $semaphore", + "Control flow test: $semaphore", () async { - var futures = >[]; + final futures = >[]; for (int i = 0; i < futures_count; i++) { futures.add(semaphore.run(() => Future.delayed(waiting))); } - var timer = Stopwatch(); + final timer = Stopwatch(); timer.start(); await Future.wait(futures); timer.stop(); @@ -31,9 +31,9 @@ void main() { ); test( - "Test semaphore acquire cancellation: $semaphore", + "Semaphore acquire cancellation test: $semaphore", () async { - var futures = >[]; + final futures = >[]; for (int i = 0; i < futures_count; i++) { futures.add(semaphore.run(() => Future.delayed(waiting))); } @@ -50,7 +50,7 @@ void main() { } test( - "BoundedSemaphore release limit", + "BoundedSemaphore release limit test", () async { final boundedSemaphore = BoundedSemaphore(concurrency); expect(boundedSemaphore.release, throwsA(isA()));