~foosoft/goldsmith

4ff59590345012cddcfbc9b9cd2213ef34fb9249 — Alex Yatskov 9 years ago 09a445f
Interface improvements
2 files changed, 27 insertions(+), 27 deletions(-)

M goldsmith.go
M types.go
M goldsmith.go => goldsmith.go +10 -10
@@ 86,14 86,14 @@ func (gs *goldsmith) NewFile(relPath string) File {
	return &file{relPath: relPath}
}

func (gs *goldsmith) applySingle(proc ProcessorSingle) {
func (gs *goldsmith) taskSingle(ts TaskerSingle) {
	s := gs.makeStage()

	var wg sync.WaitGroup
	for file := range s.input {
		wg.Add(1)
		go func(f File) {
			s.output <- proc.ProcessSingle(gs, f)
			s.output <- ts.TaskSingle(gs, f)
			wg.Done()
		}(file)
	}


@@ 104,17 104,17 @@ func (gs *goldsmith) applySingle(proc ProcessorSingle) {
	}()
}

func (gs *goldsmith) applyMultiple(proc ProcessorMultiple) {
func (gs *goldsmith) taskMultiple(tm TaskerMultiple) {
	s := gs.makeStage()
	proc.ProcessMultiple(gs, s.input, s.output)
	tm.TaskMultiple(gs, s.input, s.output)
}

func (gs *goldsmith) Apply(proc interface{}) Goldsmith {
	switch p := proc.(type) {
	case ProcessorSingle:
		gs.applySingle(p)
	case ProcessorMultiple:
		gs.applyMultiple(p)
func (gs *goldsmith) Task(task interface{}) Goldsmith {
	switch t := task.(type) {
	case TaskerSingle:
		gs.taskSingle(t)
	case TaskerMultiple:
		gs.taskMultiple(t)
	}

	return gs

M types.go => types.go +17 -17
@@ 22,33 22,33 @@

package goldsmith

type Goldsmith interface {
	Task(task interface{}) Goldsmith
	Complete(dstDir string) []File
}

type TaskerSingle interface {
	TaskSingle(ctx Context, file File) File
}

type TaskerMultiple interface {
	TaskMultiple(ctx Context, input, output chan File)
}

type Context interface {
	NewFile(path string) File
	NewFile(srcDir string) File
}

type File interface {
	Path() string
	SetPath(path string)

	Bytes() []byte
	SetBytes(bytes []byte)

	Property(key, def string) interface{}
	SetProperty(key string, value interface{})

	Error() error
	SetError(err error)

	Bytes() []byte
	SetBytes(bytes []byte)
}

type ProcessorMultiple interface {
	ProcessMultiple(ctx Context, input, output chan File)
}

type ProcessorSingle interface {
	ProcessSingle(ctx Context, file File) File
}

type Goldsmith interface {
	Apply(proc interface{}) Goldsmith
	Complete(path string) []File
}

Do not follow this link