// Start the daisy chain of workers passing the number of workers, a workerFun,
// and the data to be sent to the first worker in the chain.
// Return the final data processed by and received from the last worker in the chain
Start the daisy chain of workers passing the number of workers, a workerFun,
and the data to be sent to the first worker in the chain.
Return the final data processed by and received from the last worker in the chain
// Start the daisy chain of workers passing the number of workers a workerFun // and the data to be sent to the first worker in the chain . // Return the final data processed by and received from the last worker in the chain
func StartDaisyChainOfWorkers(numOfWorkers uint64, worker workerFun, d dataEnvelope) dataEnvelope {
	var wConfig workerConfig
	wConfig.numOfWorkers = numOfWorkers
	wConfig.wf = worker
	ch0 := make(chan dataEnvelope)
	defer close(ch0)
	var chf chan dataEnvelope
	var preCh chan dataEnvelope
	var postCh chan dataEnvelope
	preCh = ch0
	for wid := uint64(1); wid <= wConfig.numOfWorkers; wid++ {
		postCh = make(chan dataEnvelope)
		go wConfig.wf(wid, preCh, postCh)
		preCh = postCh
	}
	chf = postCh
	ch0 <- d
	return <-chf
}
func StartDaisyChainOfWorkers ( numOfWorkers uint64 , worker workerFun , d dataEnvelope ) dataEnvelope { var wConfig workerConfig wConfig . numOfWorkers = numOfWorkers wConfig . wf = worker ch0 := make ( chan dataEnvelope ) defer close ( ch0 ) var chf chan dataEnvelope var preCh chan dataEnvelope var postCh chan dataEnvelope preCh = ch0 for wid := uint64 ( 1 ) ; wid <= wConfig . numOfWorkers ; wid ++ { postCh = make ( chan dataEnvelope ) go wConfig . wf ( wid , preCh , postCh ) preCh = postCh } chf = postCh ch0 <- d return <- chf }
Start the daisy chain of workers passing the number of workers, a workerFun,
and the data to be sent to the first worker in the chain.
Start the daisy chain of workers passing the number of workers a workerFun and the data to be sent to the first worker in the chain .
// set up the worker config structure // channel used to send data to the first worker // channel used by the last worker to send data to the caller that // triggered the daisy chain // start the daisy chain of workers // chf is the channel used by the last worker to send data to the caller // that triggered the daisy chain // send the data to the first worker // receive and return the final data from the last worker