-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpubsub.ur
More file actions
29 lines (23 loc) · 896 Bytes
/
pubsub.ur
File metadata and controls
29 lines (23 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
signature S = sig
type message
end
functor Topic(M: S) = struct
open M
table subscriptions : { Client : client, Channel : channel message }
fun mapChannelsI (f : channel message -> transaction unit) : transaction unit =
queryI (SELECT subscriptions.Channel FROM subscriptions)
(fn r => f r.Subscriptions.Channel)
fun publish (m : message) : transaction unit =
mapChannelsI (fn ch => send ch m)
val subscribe : transaction (channel message) =
client <- self;
ro <- oneOrNoRows (SELECT subscriptions.Channel FROM subscriptions
WHERE subscriptions.Client = {[client]});
case ro of
None =>
ch <- channel;
Db.put subscriptions { Client = client, Channel = ch };
return ch
| Some r =>
return r.Subscriptions.Channel
end