| 124 | } |
| 125 | |
| 126 | async function next() { |
| 127 | const ee = new EventEmitter(); |
| 128 | const iterable = on(ee, 'foo'); |
| 129 | |
| 130 | process.nextTick(function() { |
| 131 | ee.emit('foo', 'bar'); |
| 132 | ee.emit('foo', 42); |
| 133 | iterable.return(); |
| 134 | }); |
| 135 | |
| 136 | const results = await Promise.all([ |
| 137 | iterable.next(), |
| 138 | iterable.next(), |
| 139 | iterable.next(), |
| 140 | ]); |
| 141 | |
| 142 | assert.deepStrictEqual(results, [{ |
| 143 | value: ['bar'], |
| 144 | done: false, |
| 145 | }, { |
| 146 | value: [42], |
| 147 | done: false, |
| 148 | }, { |
| 149 | value: undefined, |
| 150 | done: true, |
| 151 | }]); |
| 152 | |
| 153 | assert.deepStrictEqual(await iterable.next(), { |
| 154 | value: undefined, |
| 155 | done: true, |
| 156 | }); |
| 157 | } |
| 158 | |
| 159 | async function nextError() { |
| 160 | const ee = new EventEmitter(); |