File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 99 "context"
1010 "slices"
1111 "sync"
12+ "time"
1213)
1314
1415type FlowFunc [T any ] func (v T )
@@ -32,6 +33,15 @@ func (f FlowOn[T]) flow(v T) (flowed bool) {
3233 return false
3334}
3435
36+ func (f FlowOn [T ]) obsolete () bool {
37+ select {
38+ case <- f .ctx .Done ():
39+ return true
40+ default :
41+ }
42+ return false
43+ }
44+
3545type Flow [T any ] struct {
3646 ctx context.Context
3747
@@ -77,6 +87,16 @@ func (f *Flow[T]) stream() {
7787 }
7888 f .removeFinallys (notflowing )
7989 }()
90+ case <- time .Tick (3 * time .Hour ):
91+ go func () {
92+ notflowing := make (map [FlowOn [T ]]struct {})
93+ for _ , o := range f .observers () {
94+ if o .obsolete () {
95+ notflowing [o ] = struct {}{}
96+ }
97+ }
98+ f .removeFinallys (notflowing )
99+ }()
80100 }
81101 }
82102}
You can’t perform that action at this time.
0 commit comments