Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
lamnhan066 committed Mar 1, 2025
1 parent 57a64e3 commit ee06ed4
Showing 1 changed file with 17 additions and 46 deletions.
63 changes: 17 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,58 +334,29 @@ QueueStrategyDiscardIncoming()
You can extend the `QueueStrategy` and use the `queues`, `maxCount` and `queuesCount` to create your own strategy. These are how the basic strategies are created:

```dart
class QueueStrategyUnlimited<R, P> extends QueueStrategy<R, P> {
/// Unlimited queued computations.
QueueStrategyUnlimited();
class CustomQueueStrategy<R, P> extends QueueStrategy<R, P> {
CustomQueueStrategy();
@override
bool continueIfMaxCountExceeded() {
// It means the current computation should be added to the Queue
// without doing anything with the `queues`.
return true;
}
}
class QueueStrategyRemoveNewest<R, P> extends QueueStrategy<R, P> {
/// Remove the newest computation if the [maxCount] is exceeded.
QueueStrategyRemoveNewest({super.maxCount = 0});
@override
bool continueIfMaxCountExceeded() {
// Remove the last computation if the Queue (mean the newest one).
queues.removeLast();
// It means the current computation should be added to the Queue.
return true;
}
}
class QueueStrategyRemoveOldest<R, P> extends QueueStrategy<R, P> {
/// Remove the oldest computation if the [maxCount] is exceeded.
QueueStrategyRemoveOldest({super.maxCount = 0});
@override
bool continueIfMaxCountExceeded() {
// Remove the first computation if the Queue (mean the oldest one).
queues.removeFirst();
// It means the current computation should be added to the Queue.
// Determines whether a new computation should be queued
// when the maximum queue count is exceeded.
//
// This method is intended to be overridden to define
// custom queue management behavior. It allows checking
// the current state of the queue and deciding whether to allow
// additional computations beyond the specified [maxCount].
//
// Available properties for decision-making:
// - `queues`: The collection of currently queued computations.
// - `queuesCount`: The total number of computations in the queue.
// - `maxCount`: The maximum allowed number of queued computations.
// Return `true` to allow the new computation to be added to the queue,
// or `false` to prevent additional computations from being queued.
return true;
}
}
class QueueStrategyDiscardIncoming<R, P> extends QueueStrategy<R, P> {
/// Discard the new incoming computation if the [maxCount] is exceeded.
QueueStrategyDiscardIncoming({super.maxCount = 0});
@override
bool continueIfMaxCountExceeded() {
// It means the current computation should NOT be added to the Queue.
return false;
}
}
```

## Try-Catch Block
Expand Down

1 comment on commit ee06ed4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

92.05%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
lib/src
   isolate_manager.dart100%100%100%100%
   isolate_manager.dart95.97%100%100%95.97%184, 191, 197, 199, 201
lib/src/base/contactor
   isolate_contactor.dart100%100%100%100%
   isolate_contactor.dart100%100%100%100%
lib/src/base/contactor/isolate_contactor
   isolate_contactor_web.dart100%100%100%100%
   isolate_contactor_stub.dart100%100%100%100%
lib/src/base/contactor/isolate_contactor/web_platform
   isolate_contactor_web.dart91.30%100%100%91.30%64, 74
   isolate_contactor_web_worker.dart100%100%100%100%
lib/src/models
   queue_strategy.dart92.86%100%100%92.86%49, 79
   queue_strategy.dart100%100%100%100%

Please sign in to comment.