Debian Codegraph @

job.go

raw
1 package proton
2
3 import "context"
4
5 type job[In, Out any] struct {
6 ctx context.Context
7 req In
8
9 res chan Out
10 err chan error
11
12 done chan struct{}
13 }
14
15 func newJob[In, Out any](ctx context.Context, req In) *job[In, Out] {
16 return &job[In, Out]{
17 ctx: ctx,
18 req: req,
19 res: make(chan Out),
20 err: make(chan error),
21 done: make(chan struct{}),
22 }
23 }
24
25 func (job *job[In, Out]) result() (Out, error) {
26 return <-job.res, <-job.err
27 }
28
29 func (job *job[In, Out]) postSuccess(res Out) {
30 close(job.err)
31 job.res <- res
32 }
33
34 func (job *job[In, Out]) postFailure(err error) {
35 close(job.res)
36 job.err <- err
37 }
38
39 func (job *job[In, Out]) waitDone() {
40 <-job.done
41 }