(store: Store, value: Uint8Array | string, maxQueueSize: number)
| 70 | |
| 71 | /** Insert into the front of the store */ |
| 72 | export function unshift(store: Store, value: Uint8Array | string, maxQueueSize: number): Promise<void> { |
| 73 | return store(store => { |
| 74 | return keys(store).then(keys => { |
| 75 | if (keys.length >= maxQueueSize) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | // We insert with an decremented key so that the entries are popped in order |
| 80 | store.put(value, Math.min(...keys, 0) - 1); |
| 81 | return promisifyRequest(store.transaction); |
| 82 | }); |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | /** Pop the oldest value from the store */ |
| 87 | export function shift(store: Store): Promise<Uint8Array | string | undefined> { |
no test coverage detected