Skip to content

Reactor networking support #1786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: horizon
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/arr/compiler/compile-structs.arr
Original file line number Diff line number Diff line change
Expand Up @@ -3317,14 +3317,20 @@ no-globals = globals([string-dict:], [string-dict:], [string-dict:])
reactor-optional-fields = [SD.string-dict:
"last-image", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-tick", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-tick-send", {(l): A.a-name(l, A.s-type-global("Function"))},
"to-draw", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-key", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-key-send", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-raw-key", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-raw-key-send", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-mouse", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-mouse-send", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-recieve", {(l): A.a-name(l, A.s-type-global("Function"))},
"on-recieve-send", {(l): A.a-name(l, A.s-type-global("Function"))},
"stop-when", {(l): A.a-name(l, A.s-type-global("Function"))},
"seconds-per-tick", {(l): A.a-name(l, A.s-type-global("NumPositive"))},
"close-when-stop", {(l): A.a-name(l, A.s-type-global("Boolean"))},
"title", {(l): A.a-name(l, A.s-type-global("String"))},
"close-when-stop", {(l): A.a-name(l, A.s-type-global("Boolean"))}
]

reactor-fields = reactor-optional-fields.set("init", {(l): A.a-any(l)})
4 changes: 4 additions & 0 deletions src/arr/trove/reactor-events.arr
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ data RawKeyEventType:
| key-press
end

data SendingHandlerResult<S, M>:
| update(new-state :: S)
| send(new-state :: S, to-send :: M)
end
23 changes: 22 additions & 1 deletion src/js/trove/reactors.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
aliases: {
"Event": "ReactorEvent",
"RawKeyEventType": "RawKeyEventType",
"Reactor": ["local", "Reactor"]
"Reactor": ["local", "Reactor"],
"SendingHandlerResult": "SendingHandlerResult",
},
datatypes: {
"Reactor": ["data", "Reactor", ["a"], [], {
Expand Down Expand Up @@ -201,6 +202,26 @@
return makeReactorRaw(newVal, handlers, tracing, trace.concat(thisInteractTrace));
}, "interact");
}),
"interact-connect": runtime.makeMethod1(function(self, connector) {
// connector:
// register-on-message: Message -> ...
// handle-message-return: Message -> void
// dispose: () -> void
// reconnect: () -> void
checkArity(2, arguments, "interact-connect", true);
let thisInteractTrace = [];
let tracer = null;
if (tracing) {
tracer = (newVal, oldVal, k) => {
thisInteractTrace.push(newVal);
k();
};
}
return runtime.safeCall(
() => externalInteractionHandler(init, handlers, tracer, connector),
(newVal) => makeReactorRaw(newVal, handlers, tracing, trace.concat(thisInteractTrace)),
"interact-connect");
}),
"start-trace": runtime.makeMethod0(function(self) {
checkArity(1, arguments, "start-trace", true);
return makeReactorRaw(init, handlers, true, [init]);
Expand Down