I’m trying to create a custom iterable, and I’m trying to return it in a way that Observable recognises it, but I cannot figure out how to make it work. Writing this little wrapper works, but I’d like Observable to recognise the object returned from customIterable as an Iterable automatically, is that possible?
{
const customIterable = () => ({
[Symbol.asyncIterator]: function() {
let i = 0
return {
next: function() {
i++
return delay(1).then(() => ({
value: i,
done: false
}))
}
}
}
})
const iterator = customIterable()[Symbol.asyncIterator]()
while (true) {
const {done, value} = await iterator.next();
if (done) return;
yield value;
}
}
It seeeeems like it should be possible, because if I do this:
async function* t() {
await delay(1)
yield 1
await delay(1)
yield 2
await delay(1)
yield 3
}
and then just call
t()
From a cell, it properly iterates the values. What is the difference between what t() returns and what customIterable() returns that make Observable recognise the other?