watchSub method
Implementation
Future<HGrid> watchSub(HClientWatch w, List<HRef> ids, {bool checked = true}) {
if (ids.isEmpty) throw ArgumentError("ids are empty");
if (w.isClosed) throw StateError("watch is closed");
// grid meta
var b = HGridBuilder();
if (w.id != null) b.meta.add("watchId", w.id);
b.meta.add("lease", w._desiredLease);
b.meta.add("watchDis", w.dis);
// grid rows
b.addCol("id");
for (int i = 0; i < ids.length; ++i) {
b.addRow([ids[i]]);
}
// make request
return call("watchSub", b.toGrid()).then((HGrid res) {
// make sure watch is stored with its watch id
if (w.id == null) {
w._id = res.meta.getStr("watchId");
w._lease = res.meta.get("lease") as HNum?;
_watches[w.id!] = w;
}
// if checked, then check it
if (checked) {
if (res.numRows != ids.length && ids.isNotEmpty) throw UnknownRecError(id: ids[0]);
for (int i = 0; i < res.numRows; ++i) {
if (res.row(i).missing("id")) throw UnknownRecError(id: ids[i]);
}
}
return res;
}, onError: (Object e) {
if (e is CallErrError) {
// any server side error is considered close
watchClose(w, send: false);
}
throw e;
});
}