f here is expected to be a function that doesn't take long to run
(f func(), id int)
| 43 | |
| 44 | // f here is expected to be a function that doesn't take long to run |
| 45 | func (self *AsyncHandler) handle(f func(), id int) { |
| 46 | self.mutex.Lock() |
| 47 | defer self.mutex.Unlock() |
| 48 | |
| 49 | if id < self.lastId { |
| 50 | if self.onReject != nil { |
| 51 | self.onReject() |
| 52 | } |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | self.lastId = id |
| 57 | f() |
| 58 | } |