Add generic arguments to `singleCallbackPort` and `singleCompletePort` (#16)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f69a8aa..fd6401d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.1.0
+
+* Add generic arguments to `run` in `LoadBalancer` and `IsolateRunner`.
+* Add generic arguments to `singleCallbackPort` and `singleCompletePort`.
+
## 1.0.0
* Change to using `package:test` for testing.
diff --git a/lib/ports.dart b/lib/ports.dart
index 7f95e56..5ea6866 100644
--- a/lib/ports.dart
+++ b/lib/ports.dart
@@ -42,16 +42,16 @@
/// (new ReceivePort()
/// ..first.timeout(duration, () => timeoutValue).then(callback))
/// .sendPort
-SendPort singleCallbackPort(void callback(response),
- {Duration timeout, var timeoutValue}) {
+SendPort singleCallbackPort<T>(void callback(T response),
+ {Duration timeout, T timeoutValue}) {
RawReceivePort responsePort = new RawReceivePort();
Zone zone = Zone.current;
callback = zone.registerUnaryCallback(callback);
- var timer;
+ Timer timer;
responsePort.handler = (response) {
responsePort.close();
if (timer != null) timer.cancel();
- zone.runUnary(callback, response);
+ zone.runUnary(callback, response as T);
};
if (timeout != null) {
timer = new Timer(timeout, () {
@@ -87,28 +87,28 @@
/// completed in response to another event, either a port message or a timer.
///
/// Returns the `SendPort` expecting the single message.
-SendPort singleCompletePort(Completer completer,
- {callback(message), Duration timeout, onTimeout()}) {
+SendPort singleCompletePort<T>(Completer completer,
+ {callback(T message), Duration timeout, T onTimeout()}) {
if (callback == null && timeout == null) {
return singleCallbackPort(completer.complete);
}
RawReceivePort responsePort = new RawReceivePort();
- var timer;
+ Timer timer;
if (callback == null) {
- responsePort.handler = (response) {
+ responsePort.handler = (T response) {
responsePort.close();
if (timer != null) timer.cancel();
completer.complete(response);
};
} else {
Zone zone = Zone.current;
- Function action = zone.registerUnaryCallback((response) {
+ var action = zone.registerUnaryCallback((T response) {
completer.complete(new Future.sync(() => callback(response)));
});
responsePort.handler = (response) {
responsePort.close();
if (timer != null) timer.cancel();
- zone.runUnary(action, response);
+ zone.runUnary(action, response as T);
};
}
if (timeout != null) {
diff --git a/pubspec.yaml b/pubspec.yaml
index 5008df0..9ceba89 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: isolate
-version: 1.0.1-dev
+version: 1.1.0
author: Dart Team <misc@dartlang.org>
description: Utility functions and classes related to the 'dart:isolate' library.
homepage: https://github.com/dart-lang/isolate