Skip to content
Snippets Groups Projects
Unverified Commit 516a1875 authored by capossele's avatar capossele
Browse files

:zap: Change unlock order in MessageRequester StartRequest

parent 7899649f
No related branches found
No related tags found
No related merge requests found
......@@ -33,17 +33,18 @@ func New(optionalOptions ...Option) *MessageRequester {
// StartRequest initiates a regular triggering of the StartRequest event until it has been stopped using StopRequest.
func (requester *MessageRequester) StartRequest(id message.Id) {
requester.scheduledRequestsMutex.Lock()
defer requester.scheduledRequestsMutex.Unlock()
// ignore already scheduled requests
if _, exists := requester.scheduledRequests[id]; exists {
requester.scheduledRequestsMutex.Unlock()
return
}
// trigger the event and schedule the next request
// make this atomic to be sure that a successive call of StartRequest does not trigger again
requester.Events.SendRequest.Trigger(id)
requester.scheduledRequests[id] = time.AfterFunc(requester.options.retryInterval, func() { requester.reRequest(id) })
requester.scheduledRequestsMutex.Unlock()
requester.Events.SendRequest.Trigger(id)
}
// StopRequest stops requests for the given message to further happen.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment