inbox.jsView |
---|
52 | 52 | * @param {Integer} timeout |
53 | 53 | * @returns {Promise} |
54 | 54 | */ |
55 | 55 | async nextTaggedMessage (tags, timeout) { |
56 | | - if (this._waitingTags) { |
57 | | - throw new Error('already waiting on tags') |
58 | | - } |
59 | 56 | this._waitingTags = new Set(tags) |
60 | 57 | this._queue = this._queue.filter(message => !this._queueTaggedMessage(message)) |
61 | 58 | |
62 | 59 | |
72 | 69 | * Waits for the the next message if any |
73 | 70 | * @param {Integer} timeout |
74 | 71 | * @returns {Promise} |
75 | 72 | */ |
76 | | - nextMessage (timeout) { |
| 73 | + nextMessage (timeout, getCurrent = false) { |
77 | 74 | if (!this._gettingNextMessage) { |
78 | 75 | this._gettingNextMessage = this._nextMessage(timeout) |
| 76 | + } else if (!getCurrent) { |
| 77 | + throw new Error('already waiting for next message') |
79 | 78 | } |
80 | 79 | return this._gettingNextMessage |
81 | 80 | } |
82 | 81 | |
83 | | - async _nextMessage (timeout = 0) { |
| 82 | + async _nextMessage (timeout) { |
84 | 83 | await Promise.all([...this.actor._sending.values()]) |
85 | 84 | let message = this._getOldestMessage() |
86 | 85 | if (message === undefined && timeout === 0) { |
87 | 86 | return |