/
iterators.go
80 lines (72 loc) · 1.61 KB
/
iterators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package pgqueue
import (
"github.com/tcard/coro"
)
func goError(g func(func() error), returned *error) coro.GoFunc {
return func(f func()) {
g(func() error {
f()
return *returned
})
}
}
func NewDeliveryIterator(g func(func() error), f func(yield func(Delivery)) error, options ...coro.SetOption) *DeliveryIterator {
var it DeliveryIterator
it.Next = coro.New(
func(yield func()) {
it.Returned = f(func(v Delivery) {
it.Yielded = v
yield()
})
},
append(options,
coro.WithGoFunc(goError(g, &it.Returned)),
)...,
)
return &it
}
type DeliveryIterator struct {
Next coro.Resume
Yielded Delivery
Returned error
}
func NewDeliveryRowsIterator(g func(func() error), f func(yield func(DeliveryRows)) error, options ...coro.SetOption) *DeliveryRowsIterator {
var it DeliveryRowsIterator
it.Next = coro.New(
func(yield func()) {
it.Returned = f(func(v DeliveryRows) {
it.Yielded = v
yield()
})
},
append(options,
coro.WithGoFunc(goError(g, &it.Returned)),
)...,
)
return &it
}
type DeliveryRowsIterator struct {
Next coro.Resume
Yielded DeliveryRows
Returned error
}
func NewQueryWithArgsIterator(g func(func() error), f func(yield func(QueryWithArgs)) error, options ...coro.SetOption) *QueryWithArgsIterator {
var it QueryWithArgsIterator
it.Next = coro.New(
func(yield func()) {
it.Returned = f(func(v QueryWithArgs) {
it.Yielded = v
yield()
})
},
append(options,
coro.WithGoFunc(goError(g, &it.Returned)),
)...,
)
return &it
}
type QueryWithArgsIterator struct {
Next coro.Resume
Yielded QueryWithArgs
Returned error
}