forked from yuxh/gearman-go
		
	More helpful panic if you call Work() before you call Ready()
This commit is contained in:
		
							parent
							
								
									e9ce09b885
								
							
						
					
					
						commit
						24e93b4a2c
					
				@ -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