Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 27eab85
Author: Garrett <gsharp.impact@gmail.com>
Date:   Thu Apr 4 01:24:37 2024 -0500

    bump versions & update changelogs

commit 88e3334
Author: Garrett <gsharp.impact@gmail.com>
Date:   Thu Apr 4 01:17:35 2024 -0500

    update readmes

commit f2d93a0
Author: Garrett <gsharp.impact@gmail.com>
Date:   Thu Apr 4 01:11:23 2024 -0500

    fix monorepo readme pub badges

commit 32f26a6
Author: Garrett <gsharp.impact@gmail.com>
Date:   Sun Mar 31 19:59:04 2024 -0500

    Fix name ref

commit f150781
Author: Garrett <gsharp.impact@gmail.com>
Date:   Sun Mar 31 02:57:30 2024 -0500

    run once when benchmarking

commit 5c23d5e
Author: Garrett <gsharp.impact@gmail.com>
Date:   Sun Mar 31 02:40:12 2024 -0500

    feat: allow disabling deep copying items in snapshot

commit c2a2e83
Author: Garrett <gsharp.impact@gmail.com>
Date:   Sun Mar 31 01:47:53 2024 -0500

    update example to call dispose

commit 1b2c416
Author: Garrett <gsharp.impact@gmail.com>
Date:   Sun Mar 31 01:34:47 2024 -0500

    defaults

    - assert parallel > 0
    - change default retries to 0

commit 81d27e3
Author: Garrett <gsharp.impact@gmail.com>
Date:   Sat Mar 30 23:33:36 2024 -0500

    changelog
  • Loading branch information
sharpsan committed Apr 4, 2024
1 parent f771c57 commit f3721a9
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 31 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# queue_it_library

[![melos](https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square)](https://github.com/invertase/melos)
![Pub Version](https://img.shields.io/pub/v/queue_it?label=queue_it)
![Pub Version](https://img.shields.io/pub/v/flutter_queue_it?label=flutter_queue_it)
[![Pub Version](https://img.shields.io/pub/v/queue_it?label=queue_it)](https://pub.dev/packages/queue_it)
[![Pub Version](https://img.shields.io/pub/v/flutter_queue_it?label=flutter_queue_it)](https://pub.dev/packages/flutter_queue_it)
[![codecov](https://codecov.io/gh/sharpsan/queue_it_library/graph/badge.svg?token=2YLWI5OLQ3)](https://codecov.io/gh/sharpsan/queue_it_library)


Expand All @@ -12,5 +12,3 @@ This is a monorepo containing the following packages:
- [flutter_queue_it](https://github.com/sharpsan/queue_it_library/tree/main/flutter_queue_it): Provides **QueueItWidget** that rebuilds when the queue changes.

Please check out each project for more details and examples.

TODO: provide an aerial overview.
4 changes: 4 additions & 0 deletions flutter_queue_it/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.4

* Updated example project

## 0.0.3

* Added example to README.md
Expand Down
29 changes: 12 additions & 17 deletions flutter_queue_it/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,22 @@ class _ExampleAppState extends State<ExampleApp> {

await Future.delayed(duration);
},
);
)..onUpdate.listen(
(snapshot) {
String message;
if (snapshot.eventItem != null) {
message = snapshot.eventItem!.summaryTableLine;
} else {
message = snapshot.event.name;
}
log(message, name: 'QueueIt');
},
);
final _faker = Faker();
StreamSubscription<QueueSnapshot<String>>? _subscription;

@override
void initState() {
_subscription = _queue.onUpdate.listen((snapshot) {
String message;
if (snapshot.eventItem != null) {
message = snapshot.eventItem!.summaryTableLine;
} else {
message = snapshot.event.name;
}
log(message, name: 'QueueIt');
});
super.initState();
}

@override
void dispose() {
_subscription?.cancel();
_queue.dispose();
super.dispose();
}

Expand Down
2 changes: 1 addition & 1 deletion flutter_queue_it/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_queue_it
description: "Flutter integration for QueueIt. Provides a widget that automatically rebuilds when the queue is updated."
version: 0.0.3
version: 0.0.4
repository: https://github.com/sharpsan/queue_it_library
# homepage:

Expand Down
9 changes: 6 additions & 3 deletions queue_it/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## 0.0.4

* Improve: disable deep-copying items in snapshots by default, greatly improving performance. This can be controlled by setting `deepCopyItemsInSnapshot`.
## 0.0.3

* Fix: Improve order of operations when using parallel processing
* Fix: Retries
* Add: Queue date fields
* Fix: improve order of operations when using parallel processing
* Fix: retries
* Add: queue date fields
* Add: toString() summaries for queue, snapshot, and item

## 0.0.2
Expand Down
22 changes: 21 additions & 1 deletion queue_it/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ applications.

## Usage

Here's a basic example of how to use Easy Queue:
Here's a basic example of how to use QueueIt:

```dart
import 'package:queue_it/queue_it.dart';
Expand Down Expand Up @@ -60,6 +60,26 @@ void main() {
}
```

For Flutter projects you will want to use [flutter_queue_it](https://website-name.com), which listens to queue changes and rebuilds your widget tree:
```dart
QueueItWidget(
queue: _queue,
builder: (context, snapshot) {
/// `builder` will be called each time the queue updates
final items = _queue.items().toList();
return ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
final item = items[index];
return ListTile(
title: Text('Item status: ${item.status.name}'),
);
},
);
},
);
```

For a more in-depth look at how to use QueueIt, check out the example project.

## License
Expand Down
2 changes: 1 addition & 1 deletion queue_it/lib/src/models/queue_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class QueueSnapshot<T> {
final QueueItem<T>? eventItem;

/// The items in the queue at the time of the snapshot.
final List<QueueItem<T>> items;
final Iterable<QueueItem<T>> items;

/// The time the queue was started.
final DateTime? startedAt;
Expand Down
12 changes: 9 additions & 3 deletions queue_it/lib/src/queue_it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import 'package:uuid/uuid.dart';
class QueueIt<T> {
QueueIt({
required this.itemHandler,
this.retries = 3,
this.retries = 0,
this.parallel = 1,
this.useFriendlyIds = false,
}) {
this.deepCopyItemsInSnapshot = false,
}) : assert(parallel > 0, 'Parallel must be greater than 0') {
_currentBatchId = const Uuid().v4();
}

Expand All @@ -43,6 +44,9 @@ class QueueIt<T> {
/// Whether to use readable phrases as ids instead of UUIDs.
final bool useFriendlyIds;

/// Whether to deep copy items in the snapshot. Enabling this has a performance cost.
final bool deepCopyItemsInSnapshot;

/// The function that will be called to process each item in the queue.
///
/// By default the next item status will be set to [QueueItemStatus.completed] if the function
Expand Down Expand Up @@ -344,7 +348,9 @@ class QueueIt<T> {
isProcessing: _isProcessing,
currentBatchId: _currentBatchId,
eventItem: item?.copyWith(),
items: currentBatchItems.map((e) => e.copyWith()).toList(),
items: deepCopyItemsInSnapshot
? currentBatchItems.map((e) => e.copyWith()).toList()
: currentBatchItems,
startedAt: _lastStartedAt,
startedProcessingAt: _lastStartedProcessingAt,
stoppedProcessingAt: _lastStoppedProcessingAt,
Expand Down
3 changes: 2 additions & 1 deletion queue_it/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: queue_it
description: QueueIt makes dealing with queues easy. You can add multiple listeners, specify the number of concurrent items to process, view queue progress and more.
version: 0.0.3
version: 0.0.4
repository: https://github.com/sharpsan/queue_it_library

environment:
Expand All @@ -10,5 +10,6 @@ dependencies:
uuid: ^4.3.3

dev_dependencies:
benchmark_harness: ^2.2.2
lints: ^3.0.0
test: ^1.24.0
46 changes: 46 additions & 0 deletions queue_it/test/benchmark.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:benchmark_harness/benchmark_harness.dart';
import 'package:queue_it/queue_it.dart';

class QueueItBenchmark extends BenchmarkBase {
QueueIt<int>? queue;

QueueItBenchmark() : super('QueueIt');

static void main() {
QueueItBenchmark().report();
}

// The benchmark code.
@override
void run() {
for (int i = 0; i < 100; i++) {
queue?.add(i);
}
}

@override
void exercise() => run();

// Not measured setup code executed prior to the benchmark runs.
@override
void setup() {
queue = QueueIt(
deepCopyItemsInSnapshot: false,
itemHandler: (item) async {
// Do nothing.
},
)..onUpdate.listen((event) {
// Adds a subscriber so that snapshot events are sent.
});
}

// Not measured teardown code executed after the benchmark runs.
@override
void teardown() {
queue?.dispose();
}
}

void main() {
QueueItBenchmark.main();
}

0 comments on commit f3721a9

Please sign in to comment.