Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Go documentation in README #29

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 35 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# stream

--
import "."

Expand Down Expand Up @@ -50,18 +49,16 @@ var ErrFnRequired = fmt.Errorf("nil InterceptFunc, Fn is required")
```go
func Any[T any](ctx context.Context, in <-chan T) <-chan any
```

Any accepts an incoming data channel and converts the channel to a readonly
channel of the `any` type.

#### func Distribute

```go
func Distribute[T any](
ctx context.Context, in <-chan T, out ...chan<- T,
ctx context.Context, in <-chan T, out ...chan<- T,
)
```

Distribute accepts an incoming data channel and distributes the data among the
supplied outgoing data channels using a dynamic select statement.

Expand All @@ -74,7 +71,6 @@ ensure that the goroutine is properly terminated.
```go
func Drain[T any](ctx context.Context, in <-chan T)
```

Drain accepts a channel and drains the channel until the channel is closed or
the context is canceled.

Expand All @@ -83,7 +79,6 @@ the context is canceled.
```go
func FanIn[T any](ctx context.Context, in ...<-chan T) <-chan T
```

FanIn accepts incoming data channels and forwards returns a single channel that
receives all the data from the supplied channels.

Expand All @@ -95,10 +90,9 @@ ensure that the goroutine is terminated.

```go
func FanOut[T any](
ctx context.Context, in <-chan T, out ...chan<- T,
ctx context.Context, in <-chan T, out ...chan<- T,
)
```

FanOut accepts an incoming data channel and copies the data to each of the
supplied outgoing data channels.

Expand All @@ -110,12 +104,11 @@ ensure that the goroutine is properly terminated.

```go
func Intercept[T, U any](
ctx context.Context,
in <-chan T,
fn InterceptFunc[T, U],
ctx context.Context,
in <-chan T,
fn InterceptFunc[T, U],
) <-chan U
```

Intercept accepts an incoming data channel and a function literal that accepts
the incoming data and returns data of the same type and a boolean indicating
whether the data should be forwarded to the output channel. The function is
Expand All @@ -126,10 +119,9 @@ not canceled or the incoming channel remains open.

```go
func Pipe[T any](
ctx context.Context, in <-chan T, out chan<- T,
ctx context.Context, in <-chan T, out chan<- T,
)
```

Pipe accepts an incoming data channel and pipes it to the supplied outgoing data
channel.

Expand All @@ -141,25 +133,25 @@ that the goroutine is properly terminated.

```go
type DurationScaler struct {
// Interval is the number the current step must be divisible by in order
// to modify the time.Duration.
Interval int

// ScalingFactor is a value between -1 and 1 that is used to modify the
// time.Duration of a ticker or timer. The value is multiplied by
// the ScalingFactor is multiplied by the duration for scaling.
//
// For example, if the ScalingFactor is 0.5, then the duration will be
// multiplied by 0.5. If the ScalingFactor is -0.5, then the duration will
// be divided by 0.5. If the ScalingFactor is 0, then the duration will
// not be modified.
//
// A negative ScalingFactor will cause the duration to decrease as the
// step value increases causing the ticker or timer to fire more often
// and create more routines. A positive ScalingFactor will cause the
// duration to increase as the step value increases causing the ticker
// or timer to fire less often and create less routines.
ScalingFactor float64
// Interval is the number the current step must be divisible by in order
// to modify the time.Duration.
Interval int

// ScalingFactor is a value between -1 and 1 that is used to modify the
// time.Duration of a ticker or timer. The value is multiplied by
// the ScalingFactor is multiplied by the duration for scaling.
//
// For example, if the ScalingFactor is 0.5, then the duration will be
// multiplied by 0.5. If the ScalingFactor is -0.5, then the duration will
// be divided by 0.5. If the ScalingFactor is 0, then the duration will
// not be modified.
//
// A negative ScalingFactor will cause the duration to decrease as the
// step value increases causing the ticker or timer to fire more often
// and create more routines. A positive ScalingFactor will cause the
// duration to increase as the step value increases causing the ticker
// or timer to fire less often and create less routines.
ScalingFactor float64
}
```

Expand All @@ -172,18 +164,19 @@ a configured step value and modifier (between -1 and 1) value.
type InterceptFunc[T, U any] func(context.Context, T) (U, bool)
```


#### type Scaler

```go
type Scaler[T, U any] struct {
Wait time.Duration
Life time.Duration
Fn InterceptFunc[T, U]

// WaitModifier is used to modify the Wait time based on the number of
// times the Scaler has scaled up. This is useful for systems
// that are CPU bound and need to scale up more/less quickly.
WaitModifier DurationScaler
Wait time.Duration
Life time.Duration
Fn InterceptFunc[T, U]

// WaitModifier is used to modify the Wait time based on the number of
// times the Scaler has scaled up. This is useful for systems
// that are CPU bound and need to scale up more/less quickly.
WaitModifier DurationScaler
}
```

Expand All @@ -199,7 +192,7 @@ To use Scalar, simply create a new Scaler[T, U], configuring the Wait, Life, and
InterceptFunc fields. These fields are what configure the functionality of the
Scaler.

NOTE: Fn is REQUIRED!
NOTE: Fn is REQUIRED! Defaults: Wait = 1ns, Life = 1µs

After creating the Scaler instance and configuring it, call the Exec method
passing the appropriate context and input channel.
Expand All @@ -216,7 +209,6 @@ successful send occurs. (This should only loop twice).
```go
func (s Scaler[T, U]) Exec(ctx context.Context, in <-chan T) (<-chan U, error)
```

Exec starts the internal Scaler routine (the first layer of processing) and
returns the output channel where the resulting data from the Fn function will be
sent.