Skip to content

Commit

Permalink
Remove bool return in MaybeNext for gomobile compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Jan 24, 2024
1 parent c024536 commit 6c1b889
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ func (c *OnConnect) Next() *Node {
return <-c.C
}

// MaybeNext returns the next element in the channel and true, if channel is
// empty it returns nil and false.
func (c *OnConnect) MaybeNext() (*Node, bool) {
// MaybeNext returns the next element in the channel, or nil if channel is
// empty.
func (c *OnConnect) MaybeNext() *Node {
select {
case v := <-c.C:
return v, true
return v
default:
return nil, false
return nil
}
}

Expand Down Expand Up @@ -168,14 +168,14 @@ func (c *OnMessage) Next() *Message {
return <-c.C
}

// MaybeNext returns the next element in the channel and true, if channel is
// empty it returns nil and false.
func (c *OnMessage) MaybeNext() (*Message, bool) {
// MaybeNext returns the next element in the channel, or nil if channel is
// empty.
func (c *OnMessage) MaybeNext() *Message {
select {
case v := <-c.C:
return v, true
return v
default:
return nil, false
return nil
}
}

Expand Down Expand Up @@ -233,6 +233,17 @@ func (c *OnError) Next() error {
return <-c.C
}

// MaybeNext returns the next element in the channel, or nil if channel is
// empty.
func (c *OnError) MaybeNext() error {
select {
case v := <-c.C:
return v
default:
return nil
}
}

func (c *OnError) receive(err error) {
if c.Callback != nil {
c.Callback.OnError(err)
Expand Down

0 comments on commit 6c1b889

Please sign in to comment.