forked from flyteorg/flyteplugins
/
response.go
87 lines (69 loc) · 1.73 KB
/
response.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
81
82
83
84
85
86
87
package catalog
import (
"github.com/lyft/flytestdlib/bitarray"
"github.com/lyft/flytestdlib/errors"
)
type future struct {
responseStatus ResponseStatus
readyHandler ReadyHandler
err error
}
func (f future) GetResponseStatus() ResponseStatus {
return f.responseStatus
}
func (f future) GetResponseError() error {
return f.err
}
func (f *future) SetResponseStatus(status ResponseStatus) {
f.responseStatus = status
}
func (f *future) OnReady(handler ReadyHandler) {
f.readyHandler = handler
}
type downloadFuture struct {
*future
cachedResults *bitarray.BitSet
cachedCount int
resultsSize int
}
func (r downloadFuture) GetResponse() (DownloadResponse, error) {
if r.GetResponseStatus() != ResponseStatusReady {
return nil, errors.Errorf(ErrResponseNotReady, "Response is not ready yet.")
}
if r.GetResponseError() != nil {
return nil, errors.Wrapf(ErrSystemError, r.GetResponseError(), "ResponseError() is not nil.")
}
return r, nil
}
func (r downloadFuture) GetResultsSize() int {
return r.resultsSize
}
func (r downloadFuture) GetCachedResults() *bitarray.BitSet {
return r.cachedResults
}
func (r downloadFuture) GetCachedCount() int {
return r.cachedCount
}
func newDownloadFuture(status ResponseStatus, err error, cachedResults *bitarray.BitSet, resultsSize int,
cachedCount int) downloadFuture {
return downloadFuture{
future: &future{
responseStatus: status,
err: err,
},
cachedCount: cachedCount,
cachedResults: cachedResults,
resultsSize: resultsSize,
}
}
type uploadFuture struct {
*future
}
func newUploadFuture(status ResponseStatus, err error) uploadFuture {
return uploadFuture{
future: &future{
responseStatus: status,
err: err,
},
}
}