Skip to content

Commit

Permalink
fix(priorityqueue): commit session cache everytime on queue and dequeue
Browse files Browse the repository at this point in the history
  • Loading branch information
yujiosaka committed Feb 24, 2018
1 parent 99768d3 commit 203f77a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cache/session.js
Expand Up @@ -63,6 +63,7 @@ class SessionCache extends BaseCache {
const item = { value, priority };
if (queue.length && queue[queue.length - 1].priority >= priority) {
queue.push(item);
this._storage.set(key, queue);
return Promise.resolve();
}
const index = lowerBound(queue, item, (a, b) => b.priority - a.priority);
Expand All @@ -78,6 +79,7 @@ class SessionCache extends BaseCache {
*/
dequeue(key) {
const queue = this._storage.get(key) || [];
this._storage.set(key, queue);
const item = queue.shift();
if (!item) return Promise.resolve(null);
return Promise.resolve(item.value);
Expand Down

0 comments on commit 203f77a

Please sign in to comment.