Example #1
0
//  Start computation of a workflow of 'length' order dependent functions.
//  This simple example creates a list of numbers [0:length].
//      Assertions:
//          (1) Being run asynchronously.
//          (2) d.Start() has already been called.
func ExampleDaisyChain(length, id int, out [][]int, d *dispatch.Dispatch, cb *ChannelBucket, wg *sync.WaitGroup) {
	var (
		c1 = cb.Retain()
		c2 = cb.Retain()
	)
	c1.InsertToken()
	wg.Add(length)
	for i := 0; i < length; i++ {
		d.Enqueue(dispatch.NewTask(DaisyLink(ExampleDaisyFunc(id, i, &(out[id])), c1, c2, cb, wg)))
		c1 = c2
		c2 = cb.Retain()
		time.Sleep(opt.chaindelay)
	}
	wg.Done()
}
Example #2
0
func (w *Walker) VisitFile(path string, info *os.FileInfo) {
	var f = func(id int64) {
		//log.Print("stating %s", path)
		var stat, err = os.Stat(path)
		if err != nil {
			panic(err)
		}
		time.Sleep(stdDelay)
		w.lock.Lock()
		w.sizes = append(w.sizes, stat.Size)
		w.paths = append(w.paths, path)
		w.lock.Unlock()
		w.wg.Done()
	}
	w.wg.Add(1)
	w.gq.Enqueue(dispatch.NewTask(f))
}