Skip to content

Commit

Permalink
Replace vars with finals
Browse files Browse the repository at this point in the history
  • Loading branch information
Serious-senpai committed Sep 14, 2024
1 parent 041ba4c commit e2cc339
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -43,7 +43,7 @@ class Event {
Future<void> wait() async {
if (_flag) return;

var waiter = _FutureWaiter();
final waiter = _FutureWaiter();
_waiters.add(waiter);

return waiter.future;
Expand All @@ -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());
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Lock extends _Acquirable {
return;
}

var waiter = _FutureWaiter();
final waiter = _FutureWaiter();
_waiters.add(waiter);

return waiter.future;
Expand All @@ -64,7 +64,7 @@ class Lock extends _Acquirable {
if (_waiters.isEmpty) {
_locked = false;
} else {
var waiter = _getNextWaiter();
final waiter = _getNextWaiter();
waiter.complete();
}
}
Expand All @@ -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());
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/semaphore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract class _Semaphore extends _Acquirable {
return;
}

var waiter = _FutureWaiter();
final waiter = _FutureWaiter();
_waiters.add(waiter);

return waiter.future;
Expand All @@ -38,7 +38,7 @@ abstract class _Semaphore extends _Acquirable {
if (_waiters.isEmpty) {
_value++;
} else {
var waiter = _getNextWaiter();
final waiter = _getNextWaiter();
waiter.complete();
}
}
Expand All @@ -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());
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class _Acquirable {
Future<T> run<T>(Future<T> Function() func) async {
await acquire();
try {
var result = await func();
final result = await func();
return result;
} finally {
release();
Expand Down
10 changes: 5 additions & 5 deletions test/event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Future<void> mainFuture() async {

void main() {
test(
"Testing control flow: $event",
"Control flow test: $event",
() async {
var futures = <Future<void>>[];
final futures = <Future<void>>[];
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();
Expand All @@ -42,11 +42,11 @@ void main() {
);

test(
"Test event waiting cancellation: $event",
"Event waiting cancellation test: $event",
() async {
event.clear();

var futures = <Future<void>>[];
final futures = <Future<void>>[];
for (int i = 0; i < futures_count; i++) {
futures.add(sampleFuture());
}
Expand Down
10 changes: 5 additions & 5 deletions test/lock_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ void main() {
final lock = Lock();

test(
"Testing control flow: $lock",
"Control flow test: $lock",
() async {
var futures = <Future<void>>[];
final futures = <Future<void>>[];
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();
Expand All @@ -31,9 +31,9 @@ void main() {
);

test(
"Test lock acquire cancellation: $lock",
"Lock acquisition cancellation test: $lock",
() async {
var futures = <Future<void>>[];
final futures = <Future<void>>[];
for (int i = 0; i < futures_count; i++) {
futures.add(lock.run(() => Future.delayed(waiting)));
}
Expand Down
14 changes: 7 additions & 7 deletions test/semaphore_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Future<void>>[];
final futures = <Future<void>>[];
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();
Expand All @@ -31,9 +31,9 @@ void main() {
);

test(
"Test semaphore acquire cancellation: $semaphore",
"Semaphore acquire cancellation test: $semaphore",
() async {
var futures = <Future<void>>[];
final futures = <Future<void>>[];
for (int i = 0; i < futures_count; i++) {
futures.add(semaphore.run(() => Future.delayed(waiting)));
}
Expand All @@ -50,7 +50,7 @@ void main() {
}

test(
"BoundedSemaphore release limit",
"BoundedSemaphore release limit test",
() async {
final boundedSemaphore = BoundedSemaphore(concurrency);
expect(boundedSemaphore.release, throwsA(isA<BoundedSemaphoreLimitException>()));
Expand Down

0 comments on commit e2cc339

Please sign in to comment.