You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would be useful to check if the "worker pool" after a certain timeout is "finished" with all the tasks.
Example of use case:
import'dart:async';
import'dart:collection';
import'dart:mirrors';
import'package:async/async.dart';
import'package:pool/pool.dart';
voidmain() async {
Queue<String> queue =Queue();
Pool workerPool =newPool(2, timeout:Duration(seconds:1));
queue.addAll(["Hey", "there", "dart", "team"]);
// If the loop is "inactive" for 5 seconds, processing should stop.var inactivityTimer =RestartableTimer(Duration(seconds:5), () {});
while (true) {
if (!inactivityTimer.isActive) {
// RELEVANT LINE: The queue is empty, the inactivity timer has been triggered, there is currently no way besides reflection to check if the pool resources has all completed // Wait until all all work is doneif (workerPool.allocatedResources ==0) {
print("All workers are done");
break;
}
}
// The queue is empty, wait to check againif (queue.isEmpty) {
awaitFuture.delayed(Duration(seconds:5));
} else {
// We have work to do, create a new pooled resource to work on it
workerPool.withResource(() async {
awaitFuture.delayed(Duration(seconds:10));
print(queue.removeFirst())
});
inactivityTimer.reset();
}
// If we pummel the workerPool with resource requests too fast, it locks up.awaitFuture.delayed(Duration(milliseconds:10));
}
}
(Code is condensed to the basic idea, based on a web crawler I am working on).
Is this a feature that you will consider adding to this library?
The text was updated successfully, but these errors were encountered:
This would be useful to check if the "worker pool" after a certain timeout is "finished" with all the tasks.
Example of use case:
(Code is condensed to the basic idea, based on a web crawler I am working on).
Is this a feature that you will consider adding to this library?
The text was updated successfully, but these errors were encountered: