HackerTrans
TopNewTrendsCommentsPastAskShowJobs

sethvargo

no profile record

Submissions

Resourcely raises $8M seed round

techcrunch.com
3 points·by sethvargo·4 lata temu·2 comments

Perforce acquires Puppet

techcrunch.com
2 points·by sethvargo·4 lata temu·1 comments

Freenode Power to the People on Blockchain?

freenode.net
8 points·by sethvargo·5 lat temu·6 comments

comments

sethvargo
·4 lata temu·discuss
This is awesome - congratulations to the team on this raise. Very well-deserved :)
sethvargo
·4 lata temu·discuss
The context was introduced by the commenter. The original post does not use contexts. In general, there's a pretty common set of patterns in which multiple goroutines are writing data to different channels, and you need to ensure the data from those channels are processed with some level of priority.
sethvargo
·4 lata temu·discuss
Also, this isn't semantically correct. In order to ensure that `conditionaA` is _always_ preferred over `conditionB`, you must also check if `conditionA` has received a value inside of `conditionB`:

    select {
    case a := <-conditionA:
        return a
    default:
    }
    select {
    case b := <-conditionB:
      case a := <-conditionA:
          return a
      default:

      return b
    default:
    }
sethvargo
·4 lata temu·discuss
Right, which is noted in the post. That verbosity is, well, verbose. I generally need this in 20% of things I write.
sethvargo
·4 lata temu·discuss
It really doesn't though. It handles the case where the context might have expired or be cancelled, but there's still a race when entering the select between the ctx.Done() and reading from thingCh. You may end up processing one additional unit of work. In situations where the exit condition is channel-based, this won't work.

Additionally, this would only work if you had one predominant condition and that condition was context-based. If you have multiple ordered conditions upon which you want to exit, I can't think of how you'd express that as a range.
sethvargo
·4 lata temu·discuss
How would you fix that code?