diff --git a/prospect/endpoint.rkt b/prospect/endpoint.rkt index c8014c3..9ffbbd9 100644 --- a/prospect/endpoint.rkt +++ b/prospect/endpoint.rkt @@ -8,7 +8,6 @@ spawn-endpoint-group boot-endpoint-group endpoint-action? - (struct-out endpoint) endpoint-group-handle-event pretty-print-endpoint-group) @@ -36,7 +35,7 @@ [(define (prospect-pretty-print g [p (current-output-port)]) (pretty-print-endpoint-group g p))]) -;; A Handler is a (Event State -> Transition) +;; A Endpoint is a (Event State -> Transition) ;; A Transition reuses the struct from core, but with EndpointActions instead of plain Actions. ;; An EndpointAction is either an Action, or a ;; (add-endpoint (EID State -> (Values Endpoint Transition))), or a @@ -70,18 +69,7 @@ (add-endpoint? a) (delete-endpoint? a))) -;; An Endpoint represents the behaviour of an endpoint. -(struct endpoint (pre-handler ;; Handler - peri-handler ;; Handler - post-handler ;; Handler - ) #:transparent) - -(define (inert-handler e state) #f) - -(define inert-endpoint - (endpoint inert-handler - inert-handler - inert-handler)) +(define (inert-endpoint e state) #f) (define (endpoint-group-handle-event e g) (match-define (endpoint-group _ routing-table interests endpoints state) g) @@ -91,20 +79,14 @@ [(? patch?) (compute-affected-pids routing-table e)] [(message body) (tset->list (matcher-match-value routing-table (observe body) (datum-tset)))])) - (define tasks (for/list [(eid affected-eids)] - (list (if (patch? e) - (view-patch e (hash-ref interests eid matcher-empty)) - e) - eid - (hash-ref endpoints eid inert-endpoint)))) - (define t0 (transition g '())) - (define t1 (sequence-transitions t0 - (sequence-handlers tasks endpoint-pre-handler) - (sequence-handlers tasks endpoint-peri-handler) - (sequence-handlers tasks endpoint-post-handler))) - (if (eq? t1 t0) #f t1)) + (sequence-handlers g (for/list [(eid affected-eids)] + (list (if (patch? e) + (view-patch e (hash-ref interests eid matcher-empty)) + e) + eid + (hash-ref endpoints eid (lambda () inert-endpoint)))))) -(define ((sequence-handlers tasks handler-getter) g) +(define (sequence-handlers g tasks) (let/ec return (define-values (final-cumulative-patch final-actions final-g idle?) (for/fold ([cumulative-patch empty-patch] @@ -113,7 +95,7 @@ [idle? #t]) ([task tasks]) (match-define (list e eid ep) task) - (match ((handler-getter ep) e (endpoint-group-state g)) + (match (ep e (endpoint-group-state g)) [#f (values cumulative-patch actions g idle?)] [( exn ep-acs) (return ( exn (filter action? (flatten ep-acs))))] [(transition new-state ep-acs) diff --git a/prospect/examples/endpoint-example.rkt b/prospect/examples/endpoint-example.rkt index cc2d947..228b99a 100644 --- a/prospect/examples/endpoint-example.rkt +++ b/prospect/examples/endpoint-example.rkt @@ -5,8 +5,8 @@ (spawn-timer-driver) -(define ((log-it eid stage) e u) - (log-info "endpoint ~a stage ~a state ~a: ~v" eid stage u e) +(define ((log-it eid) e u) + (log-info "endpoint ~a state ~a: ~v" eid u e) (and e (transition (+ u 1) (if (equal? e (message 2)) (if (equal? eid 0) @@ -25,17 +25,13 @@ (spawn-endpoint-group 0 (add-endpoint (lambda (eid state) - (values (endpoint (log-it eid "pre") - (log-it eid "peri") - (log-it eid "post")) + (values (log-it eid) (transition state (list (sub 1) (sub 2)))))) (add-endpoint (lambda (eid state) - (values (endpoint (log-it eid "pre") - (log-it eid "peri") - (log-it eid "post")) + (values (log-it eid) (transition state (list (sub 3) (sub 2)))))))