;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2010-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

#lang syndicate

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

(require syndicate/protocol/credit)

(require/activate syndicate/distributed/server)

(spawn #:name 'loopback-client-factory
       (during/spawn (server-connection ($ address (server-loopback-connection $scope)))
         #:name address
         (assert (server-poa address))
         (on (message (message-server->poa address $p)) (send! (server-packet address p)))
         (on-start (react
                    (stop-when (asserted (observe (message-poa->server address _)))
                      (react (generic-client-session-facet
                              address
                              scope
                              (lambda (x) (send! (message-poa->server address x))))))))))
