adonis-throttle
adonis-throttle copied to clipboard
Function returning a promise
When using Redis, the function below returns a promise to the count variable
count() {
let count = this.store.get(this.key)
if (typeof count === 'undefined') {
return 0
}
return count
}
Hey @kennedyrs, thanks for reporting the bug. Redis driver uses promises because network I/O to Redis shouldn't block the Node.js event loop. This is not a problem for Memory driver since we can directly access the memory synchronously without blocking the event loop.
In fact, any driver written for external caches such as Redis, Memcached, etc. will have to be promises.
@masasron is it alright if I promisify all of the this.store
methods? Memory driver will just resolve the promise right away (e.g. wrapped in Promise.resolve()
) but it should make accessing the store much more consistent.
@AndrewJo yes I think that would be a good idea, but since this is a breaking change for the memory driver we need to release this as a minor release.