Future
callMethod(String name, [ argument ])
Source
Future callMethod(String name, [argument]) {
if (isWorker && _master != null) {
var handler = _master._requestHandlers[name];
if (handler == null) {
handler = _master._pool._methods[name];
}
var result = handler(argument);
if (result is! Future) {
return new Future.value(result);
} else {
return result;
}
} else if (_targetWorker != null) {
var handler = _targetWorker._requestHandlers[name];
if (handler == null) {
handler = _targetWorker._pool._methods[name];
}
var result = handler(argument);
if (result is! Future) {
return new Future.value(result);
} else {
return result;
}
}
var completer = new Completer();
var rid = 0;
while (_responseHandlers[rid] != null) {
rid++;
}
_responseHandlers[rid] = completer;
if (argument == null) {
_sendPort.send(
{"t": "req", "i": rid, "n": name});
} else {
_sendPort.send(
{"t": "req", "i": rid, "n": name, "a": argument});
}
return completer.future;
}