-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipe.go
112 lines (85 loc) · 3.65 KB
/
pipe.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Copyright 2017 Andreas Pannewitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Code generated by golang.org/x/tools/cmd/bundle. DO NOT EDIT.
// Package pipe provides functions
// useful to build a network of concurrent pipe processes
// the components of which are connected by channels.
//
// Just - all these beautiful and useful generic definitions
// cannot be seen via godoc here,
// as they need to be private - initially.
//
// This is due to the 'funny' way "genny" handles
// identifier-casing:
//
// If the original generic type has a public (uppercase) name,
// then generated identifiers will remain uppercase (and thus public)
// and you may never generate private non-public (lowercased) identifiers.
//
// Thus we need to start with a private id (such as `anyThing` here)
// and with private function names in order to respect Your freedom of choice.
//
// I am awfully sorry for this inconvenience
// and provide two alternatives:
//
// In the root of the repo is a complete generated version of `package pipe`
// with a public generic type (`Any`). Thus, everything public is visible
// (just: it's not intended for further use - it's way too large, isn't it?).
//
// Under the `examples` folder there are directories with samples generated
// for public types - and thus provide meaningful `godoc` documentation
// for what is used in the particular context at hand.
//
// Please enjoy to study and use what You find here.
//
// And please feel free and encouraged to suggest, improve, comment or ask,
// You'll be welcome!
//
// Think deep - code happy - be simple - see clear :-)
//
package pipe
import (
"github.com/cheekybits/genny/generic"
)
// anyThing is the generic type flowing thru the pipe network.
type anyThing generic.Type
// ===========================================================================
// Directional channel
// anyThingFrom is a receive-only anyThing channel
type anyThingFrom <-chan anyThing
// anyThingInto is a send-only anyThing channel
type anyThingInto chan<- anyThing
// ===========================================================================
// Signalling
var done chan struct{} // returned from inside to outside
var quit chan struct{} // passed from outside to inside
var stop chan struct{} // passed from outside to deep inside (kill/abort)
// anyThingWait is where a process broadcasts it's done (and then quits)
type anyThingWait <-chan struct{}
// anyThingStop is where an outer process sends it's request to stop
type anyThingStop chan<- struct{}
// ===========================================================================
// Function signatures
// Oper represents an operation
// as in anyThingDoneFunc
type anyThingOper func(a anyThing)
// Func represents a function
// usually called `act` - action
// as in anyThingPipeFunc
type anyThingFunc func(a anyThing) anyThing
// Attr returns an attribute for discrimination
type anyThingAttr func(a anyThing) interface{}
// ===========================================================================
// Process signatures
// into <- <-from
type anyThingProc func(into anyThingInto, from anyThingFrom)
// ===========================================================================
// Pipe
type anyThingChan func(args ...interface{}) anyThingFrom
type anyThingPipe func(inp anyThingFrom, args ...interface{}) anyThingFrom
type anyThingDone func(inp anyThingFrom, args ...interface{}) anyThingDone
// ===========================================================================
// Closures
type anyThingTube func(inp anyThingFrom) anyThingFrom
type anyThingFini func(inp anyThingFrom) anyThingDone