-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added toIterator method and test cases. #275
base: ee
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class EventIterator
lib/events.js
Outdated
return new Promise((resolve, reject) => { | ||
if (error) reject(error); | ||
const value = data.shift(); | ||
if (value) resolve({ value, done: false }); | ||
else promises.push({ resolve, reject }); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (error) return Promise.reject(error);
- We need flag
isPending: boolean
lib/events.js
Outdated
const data = []; | ||
const promises = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need no arrays, just single values
lib/events.js
Outdated
}, | ||
return() { | ||
handleError(); | ||
return Promise.resolve({ value: undefined, done: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Need variable or field
this.done: boolean
@GoodLuckMister still waiting for fixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Need use cases for multiple/single arguments events, from libs and platforms, node.js itself, metarhia, fastify, and libs like pino, undici, metarhia libs
- See fixed contract: Create Emitter of a healthy mind #267 (comment)
test/events.js
Outdated
// eslint-disable-next-line no-unused-vars | ||
for await (const event of iteratorWithError) { | ||
looped = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// eslint-disable-next-line no-unused-vars | |
for await (const event of iteratorWithError) { | |
looped = true; | |
} | |
for await (const event of iteratorWithError) { | |
looped = true; | |
assert.ok(event); | |
} |
test/events.js
Outdated
}); | ||
await testCase.test('error', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}); | |
await testCase.test('error', async () => { | |
}); | |
await testCase.test('error', async () => { |
lib/events.js
Outdated
@@ -1,5 +1,68 @@ | |||
'use strict'; | |||
|
|||
class EventIterator { | |||
promise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise; | |
promise = null; |
lib/events.js
Outdated
isPending = false; | ||
value = undefined; | ||
done = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is right place for iterator state done:boolean
but not ok for isPending
because it is related to one single step of iteration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
promise
is also related to a single step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value
is also attribute of a iteration step, so we can hold this.step = { pending: boolean, data: { value, done } }
, it also desirable to be private this.#step
bot better just create such a structure and pass is over functional contexts.
lib/events.js
Outdated
[Symbol.asyncIterator]() { | ||
return this; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contract mixed: AsyncItarable, AsyncItarator, AsyncItaratorStep
test/events.js
Outdated
[2], | ||
['stop'], | ||
]; | ||
for await (const event of iterator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for await (const event of iterator) { | |
for await (const event of ee) { |
npm t
)npm run fix
)