]> git.giacomolli.uk - onechat/blobdiff - subagent.go
Separate multiline Go statements
[onechat] / subagent.go
index 4cb638191eb1fab90544b016c575d074242187b0..437aeb58d589ef7a545a1cdf1a95e3787bb0a2fa 100644 (file)
@@ -23,19 +23,6 @@ const (
        subagentNameDraws = 1000
 )
 
        subagentNameDraws = 1000
 )
 
-// newSubagents returns the subagents in dir, one directory for each name. The
-// clock gives the dates of their messages, and draw gives the names of new
-// subagents.
-func newSubagents(dir string, clock func() time.Time, draw func() string) *Subagents {
-       return &Subagents{
-               dir:      dir,
-               clock:    clock,
-               draw:     draw,
-               open:     make(map[string]*Subagent),
-               reserved: make(map[string]bool),
-       }
-}
-
 // Subagents holds the subagents of one agent. Each subagent has a directory
 // named for it, which holds its log. A log takes an exclusive lock, so
 // Subagents opens the log of a name once and keeps it open until Close. Its
 // Subagents holds the subagents of one agent. Each subagent has a directory
 // named for it, which holds its log. A log takes an exclusive lock, so
 // Subagents opens the log of a name once and keeps it open until Close. Its
@@ -50,6 +37,30 @@ type Subagents struct {
        reserved map[string]bool
 }
 
        reserved map[string]bool
 }
 
+// Subagent is one subagent, its directory, and its log. Its mutex protects the
+// log, because the run of the subagent writes it while the agent reads it with
+// zoom.
+type Subagent struct {
+       name   string
+       dir    string
+       mutex  sync.Mutex
+       log    *Log
+       syncer *Syncer
+}
+
+// newSubagents returns the subagents in dir, one directory for each name. The
+// clock gives the dates of their messages, and draw gives the names of new
+// subagents.
+func newSubagents(dir string, clock func() time.Time, draw func() string) *Subagents {
+       return &Subagents{
+               dir:      dir,
+               clock:    clock,
+               draw:     draw,
+               open:     make(map[string]*Subagent),
+               reserved: make(map[string]bool),
+       }
+}
+
 // Create makes the directory and the log of a new subagent. It draws a name
 // again when the directory of the name exists.
 func (s *Subagents) Create(ctx context.Context) (*Subagent, error) {
 // Create makes the directory and the log of a new subagent. It draws a name
 // again when the directory of the name exists.
 func (s *Subagents) Create(ctx context.Context) (*Subagent, error) {
@@ -163,6 +174,7 @@ func (s *Subagents) Get(ctx context.Context, name string) (*Subagent, error) {
                log:    log,
                syncer: syncer,
        }
                log:    log,
                syncer: syncer,
        }
+
        s.open[name] = subagent
 
        return subagent, nil
        s.open[name] = subagent
 
        return subagent, nil
@@ -208,17 +220,6 @@ func (s *Subagents) Close() error {
        return err
 }
 
        return err
 }
 
-// Subagent is one subagent, its directory, and its log. Its mutex protects the
-// log, because the run of the subagent writes it while the agent reads it with
-// zoom.
-type Subagent struct {
-       name   string
-       dir    string
-       mutex  sync.Mutex
-       log    *Log
-       syncer *Syncer
-}
-
 // Append logs a message of the subagent.
 func (a *Subagent) Append(kind, text string) (Message, error) {
        a.mutex.Lock()
 // Append logs a message of the subagent.
 func (a *Subagent) Append(kind, text string) (Message, error) {
        a.mutex.Lock()