Documentation
¶
Overview ¶
Package mutable provides types to make DSP components mutable.
Each DSP component is running in its own goroutine. The only way to avoid data races and locking is to mutate components in that same goroutine. To achieve that, two things must be done: the component should be mutable and component should have defined mutations.
Mutable component ¶
Mutability is a part of DSP component structures. Nil value of mutability is immutable. To make it mutable, the one should do the following:
Mutability: mutable.Mutable()
This will make component recognized as mutable during pipe start and enable mutations execution. See examples for more details.
Example (Mutation) ¶
package main
import (
"fmt"
"pipelined.dev/pipe/mutable"
)
type mutableType struct {
mutable.Context
parameter int
}
func (v *mutableType) setParameter(value int) mutable.Mutation {
return v.Context.Mutate(func() error {
v.parameter = value
return nil
})
}
func main() {
// create new mutable component
component := &mutableType{
Context: mutable.Mutable(),
}
fmt.Println(component.parameter)
// create new mutation
mutation := component.setParameter(10)
fmt.Println(component.parameter)
// apply mutation
mutation.Apply()
fmt.Println(component.parameter)
}
Output: 0 0 10
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context [16]byte
Context can be embedded to make structure behaviour mutable.
func (Context) Mutate ¶
func (c Context) Mutate(m MutatorFunc) Mutation
Mutate associates provided mutator with mutable and return mutation.
type Destination ¶ added in v0.10.0
type Destination chan Mutations
Destination is a channel that used as source of mutations.
func NewDestination ¶ added in v0.11.0
func NewDestination() Destination
type Mutation ¶
type Mutation struct {
Context
// contains filtered or unexported fields
}
Mutation is mutator function associated with a certain mutable context.
type Mutations ¶
type Mutations map[Context][]MutatorFunc
Mutations is a set of Mutations mapped their Mutables.
type Pusher ¶ added in v0.10.0
type Pusher struct {
// contains filtered or unexported fields
}
Pusher allows to push mutations to mutable contexts.
func (Pusher) AddDestination ¶ added in v0.10.0
AddDestination adds new mapping of mutable context to destination.