summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2013-04-16 10:55:48 -0400
committerGravatar Adam Chlipala <adam@chlipala.net>2013-04-16 10:55:48 -0400
commita2386e85bac4e7da8fa1f29a676941b592d35a5d (patch)
tree2dba7c473ff3a8063145c3cd8506ac9013faa904 /lib
parent831f3ff6a5ea8fe1e727be1d9f63a2e823072457 (diff)
Basis.tryRpc
Diffstat (limited to 'lib')
-rw-r--r--lib/js/urweb.js41
-rw-r--r--lib/ur/basis.urs2
2 files changed, 32 insertions, 11 deletions
diff --git a/lib/js/urweb.js b/lib/js/urweb.js
index cc65ab8f..f56ba4c6 100644
--- a/lib/js/urweb.js
+++ b/lib/js/urweb.js
@@ -1365,7 +1365,14 @@ function redirect(s) {
window.location = s;
}
-function rc(prefix, uri, parse, k, needsSig) {
+function makeSome(isN, v) {
+ if (isN)
+ return {v: v};
+ else
+ return v;
+}
+
+function rc(prefix, uri, parse, k, needsSig, isN) {
if (!maySuspend)
er("May not 'rpc' in main thread of 'code' for <active>");
@@ -1384,18 +1391,30 @@ function rc(prefix, uri, parse, k, needsSig) {
if (isok) {
var lines = xhr.responseText.split("\n");
- if (lines.length != 2)
- whine("Bad RPC response lines");
-
- eval(lines[0]);
-
- try {
- k(parse(lines[1]));
- } catch (v) {
- doExn(v);
+ if (lines.length != 2) {
+ if (isN == null)
+ whine("Bad RPC response lines");
+ else
+ k(null);
+ } else {
+ eval(lines[0]);
+
+ try {
+ var v = parse(lines[1]);
+ try {
+ k(makeSome(isN, v));
+ } catch (v) {
+ doExn(v);
+ }
+ } catch (v) {
+ k(null);
+ }
}
} else {
- conn();
+ if (isN == null)
+ conn();
+ else
+ k(null);
}
xhrFinished(xhr);
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs
index 71320a28..59715a7e 100644
--- a/lib/ur/basis.urs
+++ b/lib/ur/basis.urs
@@ -206,6 +206,8 @@ val spawn : transaction unit -> transaction unit
val sleep : int -> transaction unit
val rpc : t ::: Type -> transaction t -> transaction t
+val tryRpc : t ::: Type -> transaction t -> transaction (option t)
+(* Returns [None] on error condition. *)
(** Channels *)