Skip to content

Commit

Permalink
MutexFunction enqueueing
Browse files Browse the repository at this point in the history
  • Loading branch information
markdicksonjr committed Jun 17, 2019
1 parent 104f2d7 commit 7aefcf6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@ type MutexFunction struct {
dispatcher *Dispatcher
}

func NewMutexFunction(handler func(data interface{}) error) *MutexFunction {
func NewMutexFunction(
handler func(data interface{}) error,
errFn func(interface{}, error),
) *MutexFunction {
s := MutexFunction{
dispatcher: NewDispatcher(1, 1, func(job Job, workerContext *Context) error {
return handler(job.Context)
}).WithJobErrFn(func(job Job, workerContext *Context, err error) {
errFn(job.Context, err)
}),
}
s.dispatcher.Run()
return &s
}

func (m *MutexFunction) Call(data interface{}) error {
m.dispatcher.EnqueueJobAllowWait(Job{
Context: data,
})
return nil
}

0 comments on commit 7aefcf6

Please sign in to comment.