Skip to content

stream.Wait() panic when callback is nil #144

Open

Description

@rhyshmwang

func Wait will panic, because callback is nil.

Can func Wait support nil callback? Maybe do nothing when callback is nil is better

st := stream.New().WithMaxGoroutines(20)

st.Go(func() stream.Callback {
    return nil
}

st.Wait()

Activity

  1. rhyshmwang commented on Nov 15, 2024

    @rhyshmwang
    Author

    There is an example. Recover() in st.Go works, but st.Wait() still panic.

    package main
    import (
        "fmt"
        "github.com/sourcegraph/conc/stream"
        "time"
    )
    func main() {
        for i := 0; i < 5; i++ {
           st := stream.New().WithMaxGoroutines(20)
           for i := 0; i < 10; i++ {
              idx := i
              st.Go(func() (callback stream.Callback) {
                 //callback = func() {} // if comment will panic
                 defer func() {
                    if err := recover(); err != nil {
                       fmt.Println("haha", err)
                    }
                 }()
                 if idx == 2 || idx == 4 {
                    panic(idx) // this panic will be recovered
                 }
                 return func() {
                 }
              })
           }
           st.Wait() // panic occurs here
        }
        time.Sleep(1 * time.Second)
    }
  2. TastyHeadphones commented on Sep 27, 2026

    @TastyHeadphones

    Looks like this is already fixed on main — callbacker skips nil callbacks (and there's a "nil callback" test). Safe to close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions