Open tylkomat opened 8 years ago
Hello,
The issue is that internally there is only one Queue object per middleware. Dynamic creation of queues is a bit more complex than it is now.
Also the question is how to define something
, i.e. how to define which part of the route to be used to limit the request: /do/:something/:other/action
The parameters are already parsed in the request object. Limiting could be done by matching parameters from an option value to the request parameters. Active limit could become an object for example:
app.use(queue({ activeLimit: {limit: 2, params: ['something'] }));
To limit only a changing something
and ignoring other
. Meaning a different value for other
will still land on the same queue if something
didn't change.
app.use(queue({ activeLimit: {limit: 2, params: ['something', 'other'] }));
In this case there should be probably a different queue for any something
and other
combination.
When a queue is empty it can be destroyed to not take up too much memory for routes which may not be accessed any more.
I would not got into the complexity of setting different limits for different parameters.
It should not used globally in this way, but as a per route middleware.
I don't know what use case you had in mind when you created this middleware. My use case was to limit access to one route which involved creation of a limited number of database artifacts. There I can't allow any concurrency since noSQL databases do not allow transactions and for every request I have to check if the item can be created. In a worst case when only one item is left to create there could come 2 or more requests at the same time and each get the answer that it is fine to create. I could involve redis for that matter but I was looking for a simple approach.
For my api
/do/:something
I would like to allow only one request per value ofsomething
.For example:
/do/something
gets through/do/something
has to wait for first request to finish/do/somethingElse
gets throughThis is a simple example. The values for
something
are unspecified values likeuuid
s.