Skip to content

Commit

Permalink
make Core hold *proc.Proc instead of proc.Proc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Barzee committed Mar 23, 2021
1 parent e456811 commit 4e32788
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// Core supports basic process control and interaction.
type Core struct {
sync.RWMutex
processes map[uuid.UUID]proc.Proc
processes map[uuid.UUID]*proc.Proc
}

// Start initiates a process.
Expand All @@ -32,21 +32,21 @@ func (c *Core) Start(cmd string, args ...string) (uuid.UUID, error) {

// Stop halts a process.
func (c *Core) Stop(id uuid.UUID) error {
var p proc.Proc
var p *proc.Proc
var err error

if p, err = c.findProcess(id); err != nil {
return c.newError("Stop", err)
}
if err = p.Kill(); err != nil {
if err = p.Stop(); err != nil {
return c.newError("Stop", err)
}
return nil
}

// Status returns the status of the process.
func (c *Core) Status(id uuid.UUID) (proc.ProcStatus, error) {
var p proc.Proc
var p *proc.Proc
var err error

if p, err = c.findProcess(id); err != nil {
Expand All @@ -58,7 +58,7 @@ func (c *Core) Status(id uuid.UUID) (proc.ProcStatus, error) {

// Query streams the output/result of a process.
func (c *Core) Query(id uuid.UUID) (<-chan proc.ProcOutput, error) {
var p proc.Proc
var p *proc.Proc
var err error

if p, err = c.findProcess(id); err != nil {
Expand All @@ -68,12 +68,12 @@ func (c *Core) Query(id uuid.UUID) (<-chan proc.ProcOutput, error) {
return p.Query()
}

func (c *Core) findProcess(id uuid.UUID) (proc.Proc, error) {
func (c *Core) findProcess(id uuid.UUID) (*proc.Proc, error) {
c.RLock()
defer c.RUnlock()
p, ok := c.processes[id]
if !ok {
return proc.Proc{}, fmt.Errorf("could not find specified process %v", id)
return nil, fmt.Errorf("could not find specified process %v", id)
}
return p, nil
}
Expand Down

0 comments on commit 4e32788

Please sign in to comment.