Answer the question
In order to leave comments, you need to log in
Access from multiple instances to a method?
Hello.
There is such a question.
There are 2 (or many) application instances. There is a service with some kind of conditional method run ()
run () launches an asynchronous task and returns some kind of response. run() twitches through the controller.
The task is to run run() once for multiple identical incoming requests .. When repeated, respectively, give the response status "in progress" or "such a request has already been completed".
How to correctly synchronize this method between many instances?
Answer the question
In order to leave comments, you need to log in
Save the state in run and check when you call it.
For example like this:
async run() {
if (this.isRunning) return 'in process'
this.isRunning = true
await doTask()
this.isRunning = false
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question