job.go 509 B

1234567891011121314151617181920212223242526272829303132333435
  1. package utl
  2. /**
  3. A job should be callable
  4. so there may be 2 types of jobs at least
  5. */
  6. type IJob interface {
  7. Exec(interface{}) error
  8. }
  9. type IJobFn func(interface{}) error
  10. type TJobChan chan *Job
  11. type TJobPool chan TJobChan
  12. func (fn IJobFn) Exec(inf interface{}) error {
  13. return fn(inf)
  14. }
  15. type Job struct {
  16. param interface{}
  17. job IJob
  18. }
  19. func NewJob(job IJob, param interface{}) *Job {
  20. return &Job{
  21. param: param,
  22. job: job,
  23. }
  24. }
  25. func (self *Job) Do() error {
  26. return self.job.Exec(self.param)
  27. }