From 7aefcf6e65bfe094be8c065f4633951d6b4278eb Mon Sep 17 00:00:00 2001 From: Mark Dickson Jr Date: Mon, 17 Jun 2019 09:55:06 -0400 Subject: [PATCH] MutexFunction enqueueing --- functions.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/functions.go b/functions.go index 084e870..7e1be76 100644 --- a/functions.go +++ b/functions.go @@ -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 +}