]> git.giacomolli.uk - onechat/blobdiff - daemon.go
Name and order the turn loop code
[onechat] / daemon.go
index 9d8402ad024de807b70ddfdfabbe4531d864e5a7..2a23dc28a4405380137213b21f9c25566c575844 100644 (file)
--- a/daemon.go
+++ b/daemon.go
@@ -101,8 +101,8 @@ func daemon(ctx context.Context, out io.Writer) (err error) {
                }
        }
 
                }
        }
 
-       return daemonServe(ctx, listener, telegram, func(notify func(Event)) (*loop, error) {
-               return newLoop(agent, memory, client, time.Now, notify)
+       return daemonServe(ctx, listener, telegram, func(notify func(Event)) (*TurnLoop, error) {
+               return newTurnLoop(agent, memory, client, time.Now, notify)
        })
 }
 
        })
 }
 
@@ -116,7 +116,7 @@ type DaemonHub struct {
 // Accept serves each client of listener until the listener closes. A new
 // client gets a ready event with the name of the agent, and a busy event when a
 // turn runs.
 // Accept serves each client of listener until the listener closes. A new
 // client gets a ready event with the name of the agent, and a busy event when a
 // turn runs.
-func (h *DaemonHub) Accept(ctx context.Context, listener net.Listener, l *loop) {
+func (h *DaemonHub) Accept(ctx context.Context, listener net.Listener, l *TurnLoop) {
        for {
                conn, err := listener.Accept()
                if err != nil {
        for {
                conn, err := listener.Accept()
                if err != nil {
@@ -163,7 +163,7 @@ func (h *DaemonHub) write(client *DaemonClient) {
 }
 
 // read runs the requests of client until it closes its connection.
 }
 
 // read runs the requests of client until it closes its connection.
-func (h *DaemonHub) read(ctx context.Context, client *DaemonClient, l *loop) {
+func (h *DaemonHub) read(ctx context.Context, client *DaemonClient, l *TurnLoop) {
        defer h.workers.Done()
        defer h.drop(client)
 
        defer h.workers.Done()
        defer h.drop(client)
 
@@ -284,7 +284,7 @@ func daemonListenSocket(path string) (net.Listener, error) {
 // daemonServe runs the loop that start makes and serves the clients of listener
 // until ctx ends or the loop fails. It closes listener. When bot is not nil, it
 // runs the bot too, and a failure of the bot stops the agent.
 // daemonServe runs the loop that start makes and serves the clients of listener
 // until ctx ends or the loop fails. It closes listener. When bot is not nil, it
 // runs the bot too, and a failure of the bot stops the agent.
-func daemonServe(ctx context.Context, listener net.Listener, bot *TelegramBot, start func(notify func(Event)) (*loop, error)) error {
+func daemonServe(ctx context.Context, listener net.Listener, bot *TelegramBot, start func(notify func(Event)) (*TurnLoop, error)) error {
        ctx, cancel := context.WithCancel(ctx)
        defer cancel()
 
        ctx, cancel := context.WithCancel(ctx)
        defer cancel()
 
@@ -338,7 +338,7 @@ func daemonServe(ctx context.Context, listener net.Listener, bot *TelegramBot, s
 }
 
 // daemonRunRequest runs one request of a client.
 }
 
 // daemonRunRequest runs one request of a client.
-func daemonRunRequest(l *loop, request SocketRequest) error {
+func daemonRunRequest(l *TurnLoop, request SocketRequest) error {
        switch request.Type {
        case "send":
                if request.Text == "" {
        switch request.Type {
        case "send":
                if request.Text == "" {