Skip to content

Commit

Permalink
chore: reorganize the extension package (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn authored Jan 31, 2025
1 parent 209586b commit 05bdc46
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 40 deletions.
2 changes: 1 addition & 1 deletion examples/fs/.gitignore → examples/file/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
fs
file
out.txt
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions extension/sink_ignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package extension

import "github.com/reugn/go-streams"

// IgnoreSink represents a simple outbound connector that discards
// all elements of a stream.
type IgnoreSink struct {
in chan any
}

var _ streams.Sink = (*IgnoreSink)(nil)

// NewIgnoreSink returns a new IgnoreSink connector.
func NewIgnoreSink() *IgnoreSink {
ignoreSink := &IgnoreSink{
in: make(chan any),
}

// asynchronously process stream data
go ignoreSink.process()

return ignoreSink
}

func (ignore *IgnoreSink) process() {
for {
_, ok := <-ignore.in
if !ok {
break
}
}
}

// In returns the input channel of the IgnoreSink connector.
func (ignore *IgnoreSink) In() chan<- any {
return ignore.in
}

// AwaitCompletion is a no-op for the IgnoreSink.
func (ignore *IgnoreSink) AwaitCompletion() {
// no-op
}
39 changes: 0 additions & 39 deletions extension/std.go → extension/sink_stdout.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,3 @@ func (stdout *StdoutSink) In() chan<- any {
func (stdout *StdoutSink) AwaitCompletion() {
<-stdout.done
}

// IgnoreSink represents a simple outbound connector that discards
// all elements of a stream.
type IgnoreSink struct {
in chan any
}

var _ streams.Sink = (*IgnoreSink)(nil)

// NewIgnoreSink returns a new IgnoreSink connector.
func NewIgnoreSink() *IgnoreSink {
ignoreSink := &IgnoreSink{
in: make(chan any),
}

// asynchronously process stream data
go ignoreSink.process()

return ignoreSink
}

func (ignore *IgnoreSink) process() {
for {
_, ok := <-ignore.in
if !ok {
break
}
}
}

// In returns the input channel of the IgnoreSink connector.
func (ignore *IgnoreSink) In() chan<- any {
return ignore.in
}

// AwaitCompletion is a no-op for the IgnoreSink.
func (ignore *IgnoreSink) AwaitCompletion() {
// no-op
}

0 comments on commit 05bdc46

Please sign in to comment.