forked from yuxh/gearman-go
		
	Merge pull request #38 from draxil/master
More helpful panic if you call Work() before you call Ready()
This commit is contained in:
		
						commit
						3232b11d83
					
				@ -22,6 +22,7 @@ type Worker struct {
 | 
			
		||||
	funcs   jobFuncs
 | 
			
		||||
	in      chan *inPack
 | 
			
		||||
	running bool
 | 
			
		||||
	ready bool
 | 
			
		||||
 | 
			
		||||
	Id           string
 | 
			
		||||
	ErrorHandler ErrorHandler
 | 
			
		||||
@ -174,12 +175,17 @@ func (worker *Worker) Ready() (err error) {
 | 
			
		||||
	for funcname, f := range worker.funcs {
 | 
			
		||||
		worker.addFunc(funcname, f.timeout)
 | 
			
		||||
	}
 | 
			
		||||
	worker.ready = true
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Main loop, block here
 | 
			
		||||
// Most of time, this should be evaluated in goroutine.
 | 
			
		||||
func (worker *Worker) Work() {
 | 
			
		||||
	if ! worker.ready {
 | 
			
		||||
		panic( "worker: Work() called before Ready()")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	defer func() {
 | 
			
		||||
		for _, a := range worker.agents {
 | 
			
		||||
			a.Close()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user