#lang imperative-syndicate

(provide (struct-out broker-loopback-connection))

(require "../client.rkt")
(require "../wire-protocol.rkt")
(require "../protocol.rkt")

(require/activate imperative-syndicate/broker/server)

(assertion-struct broker-loopback-connection (scope))

(spawn #:name 'loopback-client-factory
       (during/spawn (broker-connection ($ address (broker-loopback-connection $scope)))
         #:name address
         (assert (server-connection address scope))
         (on (message (server-outbound address $p)) (send! (broker-packet address p)))
         (generic-client-session-facet address (lambda (x) (send! (server-inbound address x))))))
