Comment

Comment by Kamq

Yeah, go's a little boilerplatey, but you have to option to run two sync things concurrently as well with something like:

    type result[T any] struct {
        el T
        err error
    }
    chanA := make(chan result[aResultType])
    chanB := make(chan result[bResultType])
    go func() {
        defer close(chanA)
        a := &blah{}
        rA, err := engine.doSomethingWithA()
        chanA <- result[aResultType]{
            el: rA,
            err: err,
        }
    }()
    go func() {
        defer close(chanB)
        b := &bloop{}
        rB, err := engine.doSomethingWithB()
        chanB <- result[bResultType]{
            el: rB,
            err: err,
        }
    }

    resultA := <- chanA
    resultB := <- chanB
parent Kamq 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton