Support other kinds of actions than patches when first spawning a process
This commit is contained in:
parent
feb55c174c
commit
506d74ed42
|
@ -148,8 +148,11 @@
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(define (general-transition? v)
|
||||||
|
(or (not v) (transition? v) (quit? v)))
|
||||||
|
|
||||||
(define (ensure-transition v)
|
(define (ensure-transition v)
|
||||||
(if (or (not v) (transition? v) (quit? v))
|
(if (general-transition? v)
|
||||||
v
|
v
|
||||||
(raise (exn:fail:contract (format "Expected transition, quit or #f; got ~v" v)
|
(raise (exn:fail:contract (format "Expected transition, quit or #f; got ~v" v)
|
||||||
(current-continuation-marks)))))
|
(current-continuation-marks)))))
|
||||||
|
@ -227,16 +230,15 @@
|
||||||
(define (make-quit #:exception [exn #f] . actions)
|
(define (make-quit #:exception [exn #f] . actions)
|
||||||
(quit exn actions))
|
(quit exn actions))
|
||||||
|
|
||||||
(define-syntax-rule (spawn-process behavior-exp initial-state-exp initial-patch-exp ...)
|
(define-syntax-rule (spawn-process behavior-exp initial-state-exp initial-action-tree-exp)
|
||||||
(spawn (lambda ()
|
(spawn (lambda ()
|
||||||
(list (patch-seq initial-patch-exp ...)
|
(list behavior-exp
|
||||||
behavior-exp
|
(transition initial-state-exp initial-action-tree-exp)))))
|
||||||
initial-state-exp))))
|
|
||||||
|
|
||||||
(define-syntax-rule (spawn/stateless behavior-exp initial-patch-exp ...)
|
(define-syntax-rule (spawn/stateless behavior-exp initial-action-tree-exp)
|
||||||
(spawn-process (stateless-behavior-wrap behavior-exp)
|
(spawn-process (stateless-behavior-wrap behavior-exp)
|
||||||
(void)
|
(void)
|
||||||
initial-patch-exp ...))
|
initial-action-tree-exp))
|
||||||
|
|
||||||
(define ((stateless-behavior-wrap b) e state)
|
(define ((stateless-behavior-wrap b) e state)
|
||||||
(match (b e)
|
(match (b e)
|
||||||
|
@ -256,9 +258,8 @@
|
||||||
|
|
||||||
(define (make-spawn-world boot-actions-thunk)
|
(define (make-spawn-world boot-actions-thunk)
|
||||||
(spawn (lambda ()
|
(spawn (lambda ()
|
||||||
(list empty-patch
|
(list world-handle-event
|
||||||
world-handle-event
|
(transition (make-world (boot-actions-thunk)) '())))))
|
||||||
(make-world (boot-actions-thunk))))))
|
|
||||||
|
|
||||||
(define (transition-bind k t0)
|
(define (transition-bind k t0)
|
||||||
(match t0
|
(match t0
|
||||||
|
@ -308,25 +309,15 @@
|
||||||
(invoke-process 'booting
|
(invoke-process 'booting
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(match (boot)
|
(match (boot)
|
||||||
[(and results (list (? patch?) (? procedure?) _))
|
[(and results (list (? procedure?) (? general-transition?)))
|
||||||
results]
|
results]
|
||||||
[other
|
[other
|
||||||
(error 'spawn
|
(error 'spawn
|
||||||
"Spawn boot procedure must yield boot spec; received ~v"
|
"Spawn boot procedure must yield boot spec; received ~v"
|
||||||
other)]))
|
other)]))
|
||||||
(lambda (results)
|
(lambda (results)
|
||||||
(match-define (list initial-patch behavior initial-state) results)
|
(match-define (list behavior initial-transition) results)
|
||||||
(define-values (new-mux new-pid patches meta-action)
|
(create-process w behavior initial-transition))
|
||||||
(mux-add-stream (world-mux w) initial-patch))
|
|
||||||
(let* ((w (update-state w new-pid initial-state))
|
|
||||||
(w (mark-pid-runnable w new-pid))
|
|
||||||
(w (struct-copy world w
|
|
||||||
[mux new-mux]
|
|
||||||
[behaviors (hash-set (world-behaviors w)
|
|
||||||
new-pid
|
|
||||||
behavior)]))
|
|
||||||
(w (deliver-patches w patches meta-action)))
|
|
||||||
w))
|
|
||||||
(lambda (exn)
|
(lambda (exn)
|
||||||
(log-error "Spawned process in world ~a died with exception:\n~a"
|
(log-error "Spawned process in world ~a died with exception:\n~a"
|
||||||
(trace-pid-stack)
|
(trace-pid-stack)
|
||||||
|
@ -352,6 +343,37 @@
|
||||||
(send-event m pid w))
|
(send-event m pid w))
|
||||||
(and send-to-meta? (message (at-meta-claim body))))]))
|
(and send-to-meta? (message (at-meta-claim body))))]))
|
||||||
|
|
||||||
|
(define (create-process w behavior initial-transition)
|
||||||
|
(if (not initial-transition)
|
||||||
|
w ;; Uh, ok
|
||||||
|
(let ()
|
||||||
|
(define-values (postprocess initial-actions)
|
||||||
|
(match (clean-transition initial-transition)
|
||||||
|
[(and q (quit exn initial-actions0))
|
||||||
|
(values (lambda (w pid)
|
||||||
|
(trace-process-step-result 'boot pid behavior (void) exn q)
|
||||||
|
(disable-process pid exn w))
|
||||||
|
(append initial-actions0 (list 'quit)))]
|
||||||
|
[(and t (transition initial-state initial-actions0))
|
||||||
|
(values (lambda (w pid)
|
||||||
|
(trace-process-step-result 'boot pid behavior (void) #f t)
|
||||||
|
(mark-pid-runnable (update-state w pid initial-state) pid))
|
||||||
|
initial-actions0)]))
|
||||||
|
(define-values (initial-patch remaining-initial-actions)
|
||||||
|
(match initial-actions
|
||||||
|
[(cons (? patch? p) rest) (values p rest)]
|
||||||
|
[other (values empty-patch other)]))
|
||||||
|
(define-values (new-mux new-pid patches meta-action)
|
||||||
|
(mux-add-stream (world-mux w) initial-patch))
|
||||||
|
(let* ((w (struct-copy world w
|
||||||
|
[mux new-mux]
|
||||||
|
[behaviors (hash-set (world-behaviors w)
|
||||||
|
new-pid
|
||||||
|
behavior)]))
|
||||||
|
(w (enqueue-actions (postprocess w new-pid) new-pid remaining-initial-actions))
|
||||||
|
(w (deliver-patches w patches meta-action)))
|
||||||
|
w))))
|
||||||
|
|
||||||
(define (deliver-patches w patches meta-action)
|
(define (deliver-patches w patches meta-action)
|
||||||
(transition (for/fold [(w w)] [(entry (in-list patches))]
|
(transition (for/fold [(w w)] [(entry (in-list patches))]
|
||||||
(match-define (cons label event) entry)
|
(match-define (cons label event) entry)
|
||||||
|
|
|
@ -99,9 +99,9 @@
|
||||||
(lambda (acs . rs) (cons (apply decrease-handler rs) acs))))
|
(lambda (acs . rs) (cons (apply decrease-handler rs) acs))))
|
||||||
(spawn demand-matcher-handle-event
|
(spawn demand-matcher-handle-event
|
||||||
d
|
d
|
||||||
(sub (projection->pattern demand-spec) #:meta-level meta-level)
|
(patch-seq (sub (projection->pattern demand-spec) #:meta-level meta-level)
|
||||||
(sub (projection->pattern supply-spec) #:meta-level meta-level)
|
(sub (projection->pattern supply-spec) #:meta-level meta-level)
|
||||||
(pub (projection->pattern supply-spec) #:meta-level meta-level)))
|
(pub (projection->pattern supply-spec) #:meta-level meta-level))))
|
||||||
|
|
||||||
;; (Matcher (Option (Setof (Listof Value))) ... -> (Option (Constreeof Action)))
|
;; (Matcher (Option (Setof (Listof Value))) ... -> (Option (Constreeof Action)))
|
||||||
;; Matcher Projection ...
|
;; Matcher Projection ...
|
||||||
|
@ -137,6 +137,6 @@
|
||||||
(when timeout-msec (message (set-timer timer-id timeout-msec 'relative)))
|
(when timeout-msec (message (set-timer timer-id timeout-msec 'relative)))
|
||||||
(spawn on-claim-handler
|
(spawn on-claim-handler
|
||||||
(matcher-empty)
|
(matcher-empty)
|
||||||
(patch base-interests (matcher-empty))
|
(patch-seq (patch base-interests (matcher-empty))
|
||||||
(patch-seq* (map projection->pattern projections))
|
(patch-seq* (map projection->pattern projections))
|
||||||
(sub (timer-expired timer-id ?)))))
|
(sub (timer-expired timer-id ?))))))
|
||||||
|
|
|
@ -90,10 +90,11 @@
|
||||||
(thread (lambda () (tcp-listener-thread control-ch listener server-addr)))
|
(thread (lambda () (tcp-listener-thread control-ch listener server-addr)))
|
||||||
(spawn tcp-listener-behavior
|
(spawn tcp-listener-behavior
|
||||||
(listener-state control-ch server-addr)
|
(listener-state control-ch server-addr)
|
||||||
(sub (advertise (observe (tcp-channel ? server-addr ?)))) ;; monitor peer
|
(patch-seq
|
||||||
(pub (advertise (tcp-channel ? server-addr ?))) ;; declare we might make connections
|
(sub (advertise (observe (tcp-channel ? server-addr ?)))) ;; monitor peer
|
||||||
(sub (tcp-accepted ? server-addr ? ?) #:meta-level 1) ;; events from driver thread
|
(pub (advertise (tcp-channel ? server-addr ?))) ;; declare we might make connections
|
||||||
))
|
(sub (tcp-accepted ? server-addr ? ?) #:meta-level 1) ;; events from driver thread
|
||||||
|
)))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Outbound Connection
|
;; Outbound Connection
|
||||||
|
@ -176,8 +177,9 @@
|
||||||
(thread (lambda () (tcp-connection-thread remote-addr local-addr control-ch cin)))
|
(thread (lambda () (tcp-connection-thread remote-addr local-addr control-ch cin)))
|
||||||
(spawn tcp-connection
|
(spawn tcp-connection
|
||||||
(connection-state control-ch cout)
|
(connection-state control-ch cout)
|
||||||
(sub (observe (tcp-channel remote-addr local-addr ?))) ;; monitor peer
|
(patch-seq
|
||||||
(pub (tcp-channel remote-addr local-addr ?)) ;; may send segments to peer
|
(sub (observe (tcp-channel remote-addr local-addr ?))) ;; monitor peer
|
||||||
(sub (tcp-channel local-addr remote-addr ?)) ;; want segments from peer
|
(pub (tcp-channel remote-addr local-addr ?)) ;; may send segments to peer
|
||||||
(sub (tcp-channel remote-addr local-addr ?) #:meta-level 1) ;; segments from driver thread
|
(sub (tcp-channel local-addr remote-addr ?)) ;; want segments from peer
|
||||||
))
|
(sub (tcp-channel remote-addr local-addr ?) #:meta-level 1) ;; segments from driver thread
|
||||||
|
)))
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(spawn timer-driver
|
(spawn timer-driver
|
||||||
0 ;; initial count
|
0 ;; initial count
|
||||||
(sub (set-timer ? ? ?))
|
(patch-seq (sub (set-timer ? ? ?))
|
||||||
(pub (timer-expired ? ?))))
|
(pub (timer-expired ? ?)))))
|
||||||
|
|
||||||
(define (timer-driver-thread-main control-ch)
|
(define (timer-driver-thread-main control-ch)
|
||||||
(define heap (make-timer-heap))
|
(define heap (make-timer-heap))
|
||||||
|
|
|
@ -69,10 +69,10 @@
|
||||||
#f]
|
#f]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(sub (udp-packet ? local-addr ?) #:meta-level 1)
|
(patch-seq (sub (udp-packet ? local-addr ?) #:meta-level 1)
|
||||||
(sub (udp-packet local-addr (udp-remote-address ? ?) ?))
|
(sub (udp-packet local-addr (udp-remote-address ? ?) ?))
|
||||||
(pub (udp-packet (udp-remote-address ? ?) local-addr ?))
|
(pub (udp-packet (udp-remote-address ? ?) local-addr ?))
|
||||||
(sub (observe (udp-packet (udp-remote-address ? ?) local-addr ?)))))
|
(sub (observe (udp-packet (udp-remote-address ? ?) local-addr ?))))))
|
||||||
|
|
||||||
;; UdpLocalAddress UdpSocket Channel -> Void
|
;; UdpLocalAddress UdpSocket Channel -> Void
|
||||||
(define (udp-receiver-thread local-addr socket control-ch)
|
(define (udp-receiver-thread local-addr socket control-ch)
|
||||||
|
|
|
@ -107,10 +107,11 @@
|
||||||
(connection-handler server-addr)))
|
(connection-handler server-addr)))
|
||||||
(spawn websocket-listener
|
(spawn websocket-listener
|
||||||
(listener-state shutdown-procedure server-addr)
|
(listener-state shutdown-procedure server-addr)
|
||||||
(sub (advertise (observe (websocket-message ? server-addr ?)))) ;; monitor peer
|
(patch-seq
|
||||||
(pub (advertise (websocket-message ? server-addr ?))) ;; declare we might make connections
|
(sub (advertise (observe (websocket-message ? server-addr ?)))) ;; monitor peer
|
||||||
(sub (websocket-connection ? server-addr ? ? ?) #:meta-level 1) ;; events from driver thd
|
(pub (advertise (websocket-message ? server-addr ?))) ;; declare we might make connections
|
||||||
))
|
(sub (websocket-connection ? server-addr ? ? ?) #:meta-level 1) ;; events from driver thd
|
||||||
|
)))
|
||||||
|
|
||||||
(define (spawn-websocket-connection local-addr remote-addr)
|
(define (spawn-websocket-connection local-addr remote-addr)
|
||||||
(match-define (websocket-remote-server url) remote-addr)
|
(match-define (websocket-remote-server url) remote-addr)
|
||||||
|
@ -136,8 +137,9 @@
|
||||||
(transition (cons m buffered-messages-rev) '())]
|
(transition (cons m buffered-messages-rev) '())]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
'()
|
'()
|
||||||
(sub (websocket-connection id local-addr remote-addr ? control-ch) #:meta-level 1)
|
(patch-seq
|
||||||
(sub (websocket-message local-addr remote-addr ?))))
|
(sub (websocket-connection id local-addr remote-addr ? control-ch) #:meta-level 1)
|
||||||
|
(sub (websocket-message local-addr remote-addr ?)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Connection
|
;; Connection
|
||||||
|
@ -173,8 +175,9 @@
|
||||||
(define (spawn-connection local-addr remote-addr id c control-ch)
|
(define (spawn-connection local-addr remote-addr id c control-ch)
|
||||||
(spawn websocket-connection-behaviour
|
(spawn websocket-connection-behaviour
|
||||||
(connection-state local-addr remote-addr c control-ch)
|
(connection-state local-addr remote-addr c control-ch)
|
||||||
(sub (observe (websocket-message remote-addr local-addr ?))) ;; monitor peer
|
(patch-seq
|
||||||
(pub (websocket-message remote-addr local-addr ?)) ;; may send messages to peer
|
(sub (observe (websocket-message remote-addr local-addr ?))) ;; monitor peer
|
||||||
(sub (websocket-message local-addr remote-addr ?)) ;; want segments from peer
|
(pub (websocket-message remote-addr local-addr ?)) ;; may send messages to peer
|
||||||
(sub (websocket-incoming-message id ?) #:meta-level 1) ;; segments from driver thd
|
(sub (websocket-message local-addr remote-addr ?)) ;; want segments from peer
|
||||||
))
|
(sub (websocket-incoming-message id ?) #:meta-level 1) ;; segments from driver thd
|
||||||
|
)))
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
(struct-out delete-endpoint)
|
(struct-out delete-endpoint)
|
||||||
make-endpoint-group
|
make-endpoint-group
|
||||||
spawn-endpoint-group
|
spawn-endpoint-group
|
||||||
|
boot-endpoint-group
|
||||||
endpoint-action?
|
endpoint-action?
|
||||||
(struct-out endpoint)
|
(struct-out endpoint)
|
||||||
endpoint-group-handle-event
|
endpoint-group-handle-event
|
||||||
|
@ -50,20 +51,19 @@
|
||||||
(hash)
|
(hash)
|
||||||
initial-state))
|
initial-state))
|
||||||
|
|
||||||
(define-syntax-rule (spawn-endpoint-group initial-state add-endpoint-instruction ...)
|
(define-syntax-rule (spawn-endpoint-group initial-state action-constree ...)
|
||||||
(<spawn> (lambda ()
|
(<spawn> (lambda () (boot-endpoint-group initial-state (list action-constree ...)))))
|
||||||
(define-values (final-cumulative-patch final-actions final-g)
|
|
||||||
(interpret-endpoint-actions empty-patch
|
(define (boot-endpoint-group initial-state initial-actions)
|
||||||
'()
|
(define-values (final-cumulative-patch final-actions final-g)
|
||||||
(make-endpoint-group initial-state)
|
(interpret-endpoint-actions empty-patch
|
||||||
-1
|
'()
|
||||||
(list add-endpoint-instruction ...)))
|
(make-endpoint-group initial-state)
|
||||||
(when (not (null? final-actions))
|
-1
|
||||||
(error 'spawn-endpoint-group
|
initial-actions))
|
||||||
"Unexpected initial actions: ~v" final-actions))
|
(list endpoint-group-handle-event
|
||||||
(list final-cumulative-patch
|
(transition final-g (incorporate-cumulative-patch final-actions
|
||||||
endpoint-group-handle-event
|
final-cumulative-patch))))
|
||||||
final-g))))
|
|
||||||
|
|
||||||
(define (endpoint-action? a)
|
(define (endpoint-action? a)
|
||||||
(or (action? a)
|
(or (action? a)
|
||||||
|
|
|
@ -12,14 +12,15 @@
|
||||||
[(message (at-meta (mouse-event _ _ _ "button-down"))) (transition s (callback))]
|
[(message (at-meta (mouse-event _ _ _ "button-down"))) (transition s (callback))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(let ((label-image (text label font-size foreground)))
|
(patch-seq
|
||||||
(update-window name x y
|
(let ((label-image (text label font-size foreground)))
|
||||||
(overlay label-image
|
(update-window name x y
|
||||||
(rectangle (+ (image-width label-image) 20)
|
(overlay label-image
|
||||||
(+ (image-height label-image) 20)
|
(rectangle (+ (image-width label-image) 20)
|
||||||
"solid"
|
(+ (image-height label-image) 20)
|
||||||
background))))
|
"solid"
|
||||||
(sub (mouse-event ? ? name ?) #:meta-level 1)))
|
background))))
|
||||||
|
(sub (mouse-event ? ? name ?) #:meta-level 1))))
|
||||||
|
|
||||||
(define (draggable-shape name orig-x orig-y image)
|
(define (draggable-shape name orig-x orig-y image)
|
||||||
(struct idle (ticks x y) #:transparent)
|
(struct idle (ticks x y) #:transparent)
|
||||||
|
@ -45,9 +46,9 @@
|
||||||
(mouse-sub name)))]
|
(mouse-sub name)))]
|
||||||
[(_ _) #f])
|
[(_ _) #f])
|
||||||
(idle 0 orig-x orig-y)
|
(idle 0 orig-x orig-y)
|
||||||
(sub (tick-event) #:meta-level 1)
|
(patch-seq (sub (tick-event) #:meta-level 1)
|
||||||
(mouse-sub name)
|
(mouse-sub name)
|
||||||
(move-to orig-x orig-y)))
|
(move-to orig-x orig-y))))
|
||||||
|
|
||||||
(big-bang-world #:width 640
|
(big-bang-world #:width 640
|
||||||
#:height 480
|
#:height 480
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
(assert (box-state new-value))))]
|
(assert (box-state new-value))))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
0
|
0
|
||||||
(sub (set-box ?))
|
(patch-seq (sub (set-box ?))
|
||||||
(assert (box-state 0)))
|
(assert (box-state 0))))
|
||||||
|
|
||||||
(spawn (lambda (e s)
|
(spawn (lambda (e s)
|
||||||
(match e
|
(match e
|
||||||
|
@ -23,4 +23,4 @@
|
||||||
(message (set-box (+ v 1)))))]
|
(message (set-box (+ v 1)))))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(sub (box-state ?)))
|
(patch-seq (sub (box-state ?))))
|
||||||
|
|
|
@ -19,8 +19,9 @@
|
||||||
(flush-output)
|
(flush-output)
|
||||||
#f]
|
#f]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(sub (external-event (read-bytes-line-evt (current-input-port) 'any) ?)
|
(patch-seq
|
||||||
#:meta-level 1)
|
(sub (external-event (read-bytes-line-evt (current-input-port) 'any) ?)
|
||||||
(sub (tcp-channel remote-handle local-handle ?))
|
#:meta-level 1)
|
||||||
(sub (advertise (tcp-channel remote-handle local-handle ?)))
|
(sub (tcp-channel remote-handle local-handle ?))
|
||||||
(pub (tcp-channel local-handle remote-handle ?)))
|
(sub (advertise (tcp-channel remote-handle local-handle ?)))
|
||||||
|
(pub (tcp-channel local-handle remote-handle ?))))
|
||||||
|
|
|
@ -30,13 +30,14 @@
|
||||||
(list (for/list [(who arrived)] (say who "arrived."))
|
(list (for/list [(who arrived)] (say who "arrived."))
|
||||||
(for/list [(who departed)] (say who "departed.")))))]
|
(for/list [(who departed)] (say who "departed.")))))]
|
||||||
[#f #f]))
|
[#f #f]))
|
||||||
(sub `(,? says ,?)) ;; read actual chat messages
|
(patch-seq
|
||||||
(sub (advertise `(,? says ,?))) ;; observe peer presence
|
(sub `(,? says ,?)) ;; read actual chat messages
|
||||||
(pub `(,user says ,?)) ;; advertise our presence
|
(sub (advertise `(,? says ,?))) ;; observe peer presence
|
||||||
(sub (tcp-channel them us ?) #:meta-level 1) ;; read from remote client
|
(pub `(,user says ,?)) ;; advertise our presence
|
||||||
(sub (advertise (tcp-channel them us ?)) #:meta-level 1) ;; monitor remote client
|
(sub (tcp-channel them us ?) #:meta-level 1) ;; read from remote client
|
||||||
(pub (tcp-channel us them ?) #:meta-level 1) ;; we will write to remote client
|
(sub (advertise (tcp-channel them us ?)) #:meta-level 1) ;; monitor remote client
|
||||||
)))
|
(pub (tcp-channel us them ?) #:meta-level 1) ;; we will write to remote client
|
||||||
|
))))
|
||||||
|
|
||||||
(spawn-tcp-driver)
|
(spawn-tcp-driver)
|
||||||
(spawn-world
|
(spawn-world
|
||||||
|
|
|
@ -94,8 +94,8 @@
|
||||||
(transition-bind (process-suggestion suggestion) t)))]
|
(transition-bind (process-suggestion suggestion) t)))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(db-state (load-epoch directory) directory (set))
|
(db-state (load-epoch directory) directory (set))
|
||||||
(sub (observe (binding ? ? ? ?)))
|
(patch-seq (sub (observe (binding ? ? ? ?)))
|
||||||
(sub (update ? ? ? ?))))
|
(sub (update ? ? ? ?)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@
|
||||||
other-epoch other-version other-value))])]
|
other-epoch other-version other-value))])]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(assert (update key epoch version value))
|
(patch-seq (assert (update key epoch version value))
|
||||||
(sub (binding key ? ? ?))))
|
(sub (binding key ? ? ?)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,6 @@
|
||||||
(transition state (message (tcp-channel dst src bs)))]
|
(transition state (message (tcp-channel dst src bs)))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(sub (advertise (tcp-channel c server-id ?)))
|
(patch-seq (sub (advertise (tcp-channel c server-id ?)))
|
||||||
(sub (tcp-channel c server-id ?))
|
(sub (tcp-channel c server-id ?))
|
||||||
(pub (tcp-channel server-id c ?)))))
|
(pub (tcp-channel server-id c ?))))))
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
(when (message? e) (log-info "general: ~v" e))
|
(when (message? e) (log-info "general: ~v" e))
|
||||||
#f)
|
#f)
|
||||||
(void)
|
(void)
|
||||||
(sub ?)
|
(patch-seq (sub ?)
|
||||||
(unsub (observe ?))
|
(unsub (observe ?))
|
||||||
(unsub (at-meta ?)))
|
(unsub (at-meta ?))))
|
||||||
|
|
||||||
(spawn-endpoint-group 0
|
(spawn-endpoint-group 0
|
||||||
(add-endpoint
|
(add-endpoint
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
|
|
||||||
(spawn-world (spawn r (void) (sub ?))
|
(spawn-world (spawn r (void) (sub ?))
|
||||||
(spawn b 0))
|
(spawn b 0 '()))
|
||||||
|
|
||||||
(define (echoer e s)
|
(define (echoer e s)
|
||||||
(match e
|
(match e
|
||||||
|
@ -38,7 +38,8 @@
|
||||||
(transition s (message `(print (got-line ,line))))]
|
(transition s (message `(print (got-line ,line))))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
|
|
||||||
(spawn echoer (void)
|
(spawn echoer
|
||||||
|
(void)
|
||||||
(sub (external-event (read-line-evt (current-input-port) 'any) ?) #:meta-level 1))
|
(sub (external-event (read-line-evt (current-input-port) 'any) ?) #:meta-level 1))
|
||||||
|
|
||||||
(define (ticker e s)
|
(define (ticker e s)
|
||||||
|
@ -56,9 +57,10 @@
|
||||||
|
|
||||||
(spawn-timer-driver)
|
(spawn-timer-driver)
|
||||||
(message (set-timer 'tick 1000 'relative))
|
(message (set-timer 'tick 1000 'relative))
|
||||||
(spawn ticker 1
|
(spawn ticker
|
||||||
(sub (observe (set-timer ? ? ?)))
|
1
|
||||||
(sub (timer-expired 'tick ?)))
|
(patch-seq (sub (observe (set-timer ? ? ?)))
|
||||||
|
(sub (timer-expired 'tick ?))))
|
||||||
|
|
||||||
(define (printer e s)
|
(define (printer e s)
|
||||||
(match e
|
(match e
|
||||||
|
@ -67,4 +69,6 @@
|
||||||
#f]
|
#f]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
|
|
||||||
(spawn printer (void) (sub `(print ,?)))
|
(spawn printer
|
||||||
|
(void)
|
||||||
|
(sub `(print ,?)))
|
||||||
|
|
|
@ -9,5 +9,5 @@
|
||||||
[1 (transition 2 (retract 'a #:meta-level 1))]
|
[1 (transition 2 (retract 'a #:meta-level 1))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
0
|
0
|
||||||
(assert 'a #:meta-level 1)
|
(patch-seq (assert 'a #:meta-level 1)
|
||||||
(assert (observe 'a) #:meta-level 1)))
|
(assert (observe 'a) #:meta-level 1))))
|
||||||
|
|
|
@ -59,12 +59,14 @@
|
||||||
(run-ground (spawn quasi-spy (void) (sub ?))
|
(run-ground (spawn quasi-spy (void) (sub ?))
|
||||||
(spawn-timer-driver)
|
(spawn-timer-driver)
|
||||||
(message (set-timer 'tick 1000 'relative))
|
(message (set-timer 'tick 1000 'relative))
|
||||||
(spawn ticker 1
|
(spawn ticker
|
||||||
(sub (observe (set-timer ? ? ?)))
|
1
|
||||||
(sub (timer-expired 'tick ?)))
|
(patch-seq (sub (observe (set-timer ? ? ?)))
|
||||||
|
(sub (timer-expired 'tick ?))))
|
||||||
(spawn-world (spawn r (void) (sub ?))
|
(spawn-world (spawn r (void) (sub ?))
|
||||||
(spawn b 0))
|
(spawn b 0 '()))
|
||||||
(spawn echoer (void)
|
(spawn echoer
|
||||||
|
(void)
|
||||||
(sub (external-event (read-line-evt (current-input-port) 'any) ?)
|
(sub (external-event (read-line-evt (current-input-port) 'any) ?)
|
||||||
#:meta-level 1))
|
#:meta-level 1))
|
||||||
(spawn printer (void) (sub `(print ,?))))
|
(spawn printer (void) (sub `(print ,?))))
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
(assert `(parent-count ,new-count))))]
|
(assert `(parent-count ,new-count))))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
0
|
0
|
||||||
(sub `(parent ,? ,?))
|
(patch-seq (sub `(parent ,? ,?))
|
||||||
(assert `(parent-count 0)))
|
(assert `(parent-count 0))))
|
||||||
|
|
||||||
(define (insert-record record . monitors)
|
(define (insert-record record . monitors)
|
||||||
(printf "Record ~v inserted, depending on ~v\n" record monitors)
|
(printf "Record ~v inserted, depending on ~v\n" record monitors)
|
||||||
|
@ -36,9 +36,9 @@
|
||||||
(quit)]
|
(quit)]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(assert record)
|
(patch-seq (assert record)
|
||||||
(sub `(retract ,record))
|
(sub `(retract ,record))
|
||||||
(patch-seq* (map sub monitors))))
|
(patch-seq* (map sub monitors)))))
|
||||||
|
|
||||||
(insert-record `(parent john douglas))
|
(insert-record `(parent john douglas))
|
||||||
(insert-record `(parent bob john))
|
(insert-record `(parent bob john))
|
||||||
|
@ -91,8 +91,8 @@
|
||||||
`(parent ,A ,C)
|
`(parent ,A ,C)
|
||||||
`(ancestor ,C ,B)))))))
|
`(ancestor ,C ,B)))))))
|
||||||
(void)
|
(void)
|
||||||
(sub `(parent ,A ,C))
|
(patch-seq (sub `(parent ,A ,C))
|
||||||
(sub `(ancestor ,C ,?)))))]
|
(sub `(ancestor ,C ,?))))))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(sub `(parent ,? ,?)))
|
(sub `(parent ,? ,?)))
|
||||||
|
@ -128,10 +128,11 @@
|
||||||
;; (assert `(ancestor ,A ,B))))]
|
;; (assert `(ancestor ,A ,B))))]
|
||||||
;; [_ #f]))
|
;; [_ #f]))
|
||||||
;; (matcher-empty)
|
;; (matcher-empty)
|
||||||
;; (sub `(parent ,A ,B))
|
;; (patch-seq
|
||||||
;; (sub `(parent ,A ,?))
|
;; (sub `(parent ,A ,B))
|
||||||
;; (sub `(ancestor ,? ,B))
|
;; (sub `(parent ,A ,?))
|
||||||
;; (pub `(ancestor ,A ,B)))))
|
;; (sub `(ancestor ,? ,B))
|
||||||
|
;; (pub `(ancestor ,A ,B))))))
|
||||||
|
|
||||||
(spawn (lambda (e s)
|
(spawn (lambda (e s)
|
||||||
(when (patch? e) (pretty-print-patch e))
|
(when (patch? e) (pretty-print-patch e))
|
||||||
|
@ -143,11 +144,10 @@
|
||||||
(define id (gensym 'after))
|
(define id (gensym 'after))
|
||||||
(if (zero? msec)
|
(if (zero? msec)
|
||||||
(thunk)
|
(thunk)
|
||||||
(list
|
(spawn (lambda (e s) (and (message? e) (quit (thunk))))
|
||||||
(spawn (lambda (e s) (and (message? e) (quit (thunk))))
|
(void)
|
||||||
(void)
|
(list (message (set-timer id msec 'relative))
|
||||||
(sub (timer-expired id ?)))
|
(sub (timer-expired id ?))))))
|
||||||
(message (set-timer id msec 'relative)))))
|
|
||||||
|
|
||||||
(define use-delays? #t)
|
(define use-delays? #t)
|
||||||
|
|
||||||
|
|
|
@ -72,8 +72,8 @@
|
||||||
(transition-bind (process-suggestion suggestion) t)))]
|
(transition-bind (process-suggestion suggestion) t)))]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(db-state 0 (hash) (set))
|
(db-state 0 (hash) (set))
|
||||||
(sub (observe (binding ? ? ? ?)))
|
(patch-seq (sub (observe (binding ? ? ? ?)))
|
||||||
(sub (update ? ? ? ?))))
|
(sub (update ? ? ? ?)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@
|
||||||
other-epoch other-version other-value))])]
|
other-epoch other-version other-value))])]
|
||||||
[_ #f]))
|
[_ #f]))
|
||||||
(void)
|
(void)
|
||||||
(assert (update key epoch version value))
|
(patch-seq (assert (update key epoch version value))
|
||||||
(sub (binding key ? ? ?))))
|
(sub (binding key ? ? ?)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
(format "msg ~v\n" n))))))]))
|
(format "msg ~v\n" n))))))]))
|
||||||
(spawn connection-handler
|
(spawn connection-handler
|
||||||
0
|
0
|
||||||
(sub (advertise (tcp-channel c server-id ?)))
|
(patch-seq (sub (advertise (tcp-channel c server-id ?)))
|
||||||
(sub (tcp-channel c server-id ?))
|
(sub (tcp-channel c server-id ?))
|
||||||
(pub (tcp-channel server-id c ?))))
|
(pub (tcp-channel server-id c ?)))))
|
||||||
|
|
||||||
(spawn-demand-matcher (advertise (tcp-channel (?!) server-id ?))
|
(spawn-demand-matcher (advertise (tcp-channel (?!) server-id ?))
|
||||||
(observe (tcp-channel (?!) server-id ?))
|
(observe (tcp-channel (?!) server-id ?))
|
||||||
|
|
|
@ -21,9 +21,9 @@
|
||||||
#f)]))
|
#f)]))
|
||||||
(spawn connection-handler
|
(spawn connection-handler
|
||||||
0
|
0
|
||||||
(sub (advertise (websocket-message c server-id ?)))
|
(patch-seq (sub (advertise (websocket-message c server-id ?)))
|
||||||
(sub (websocket-message c server-id ?))
|
(sub (websocket-message c server-id ?))
|
||||||
(pub (websocket-message server-id c ?))))
|
(pub (websocket-message server-id c ?)))))
|
||||||
|
|
||||||
(spawn-demand-matcher (advertise (websocket-message (?! any-client) server-id ?))
|
(spawn-demand-matcher (advertise (websocket-message (?! any-client) server-id ?))
|
||||||
(observe (websocket-message (?! any-client) server-id ?))
|
(observe (websocket-message (?! any-client) server-id ?))
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
#f)]))
|
#f)]))
|
||||||
(spawn connection-handler
|
(spawn connection-handler
|
||||||
0
|
0
|
||||||
(sub (advertise (websocket-message c server-id ?)))
|
(patch-seq (sub (advertise (websocket-message c server-id ?)))
|
||||||
(sub (websocket-message c server-id ?))
|
(sub (websocket-message c server-id ?))
|
||||||
(pub (websocket-message server-id c ?))))
|
(pub (websocket-message server-id c ?)))))
|
||||||
|
|
||||||
(spawn-demand-matcher (advertise (websocket-message (?! any-client) server-id ?))
|
(spawn-demand-matcher (advertise (websocket-message (?! any-client) server-id ?))
|
||||||
(observe (websocket-message (?! any-client) server-id ?))
|
(observe (websocket-message (?! any-client) server-id ?))
|
||||||
|
|
Loading…
Reference in New Issue