Skip to content

Commit

Permalink
Merge pull request #2 from TransactPRO/add-apply-tube
Browse files Browse the repository at this point in the history
Added apply tube to beanstalk Conn
  • Loading branch information
OlegKoncevoy authored Aug 15, 2019
2 parents 8c75148 + ee5e6d6 commit 7903f9d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,52 @@ func NewConn(conn io.ReadWriteCloser) *Conn {
return c
}

// ApplyTube: call UseTube and WatchTube
func (c *Conn) ApplyTube(tubeName string) error {
var err error
if err = c.UseTube(tubeName); err != nil {
return err
}
err = c.WatchTube(tubeName)
return err
}

// UseTube: set tube to send data into
func (c *Conn) UseTube(tubeName string) error {
var err error
if err = checkName(tubeName); err != nil {
return err
}
c.Tube = Tube{c, tubeName}
c.used = tubeName
c.printLine("use", tubeName)
return err
}

// WatchTube: add tubeName to listen from
func (c *Conn) WatchTube(tubeName string) error {
var err error
if err = checkName(tubeName); err != nil {
return err
}
c.TubeSet.Name[tubeName] = true
c.watched[tubeName] = true
c.printLine("watch", tubeName)
return err
}

// UnwatchTube: undo WatchTube
func (c *Conn) UnwatchTube(tubeName string) error {
var err error
if err = checkName(tubeName); err != nil {
return err
}
c.TubeSet.Name[tubeName] = false
c.watched[tubeName] = false
c.printLine("ignore", tubeName)
return err
}

// Dial connects to the given address on the given network using net.Dial
// and then returns a new Conn for the connection.
func Dial(network, addr string) (*Conn, error) {
Expand Down

0 comments on commit 7903f9d

Please sign in to comment.