X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/d50c22617aafed0d3d87bf4596e933b343a10b60..1379d7d0d0173416237ddf8ebe820743d2cecfa6:/daemon.go?ds=inline diff --git a/daemon.go b/daemon.go index 9d8402a..2a23dc2 100644 --- 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. -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 { @@ -163,7 +163,7 @@ func (h *DaemonHub) write(client *DaemonClient) { } // 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) @@ -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. -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() @@ -338,7 +338,7 @@ func daemonServe(ctx context.Context, listener net.Listener, bot *TelegramBot, s } // 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 == "" {