forked from andradeandrey/fwk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.go
47 lines (37 loc) · 1.68 KB
/
io.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
package fwk
// StreamControl provides concurrency-safe control to input and output streamers.
type StreamControl struct {
Ports []Port // list of ports streamers will read-from or write-to
Ctx chan Context // contexts to read-from or write-to
Err chan error // errors encountered during reading-from or writing-to
Quit chan struct{} // closed to signify in/out-streamers should stop reading-from/writing-to
}
// InputStreamer reads data from the underlying io.Reader
// and puts it into fwk's Context
type InputStreamer interface {
// Connect connects the InputStreamer to the underlying io.Reader,
// and configure it to only read-in the data specified in ports.
Connect(ports []Port) error
// Read reads the data from the underlying io.Reader
// and puts it in the store associated with the fwk.Context ctx
Read(ctx Context) error
// Disconnect disconnects the InputStreamer from the underlying io.Reader,
// possibly computing some statistics data.
// It does not (and can not) close the underlying io.Reader.
Disconnect() error
}
// OutputStreamer gets data from the Context
// and writes it to the underlying io.Writer
type OutputStreamer interface {
// Connect connects the OutputStreamer to the underlying io.Writer,
// and configure it to only write-out the data specified in ports.
Connect(ports []Port) error
// Write gets the data from the store associated with the fwk.Context ctx
// and writes it to the underlying io.Writer
Write(ctx Context) error
// Disconnect disconnects the OutputStreamer from the underlying io.Writer,
// possibly computing some statistics data.
// It does not (and can not) close the underlying io.Writer.
Disconnect() error
}
// EOF