Async generator return value as result tree
Zolmeister opened this issue · comments
It looks like the return value for async generator components is being skipped
Root = ->
yield await Promise.resolve null
# yield h 'div', 'abc'
return h 'div', 'abc'
Expected: <div>abc</div>
Received:
When you have
async function* Root (props) {
yield await Promise.resolve(null)
yield await h('div', {}, 'abc')
}
We get the value from the generator: {value: undefined, done: true}
that is equally true for
async function* Root (props) {
yield await Promise.resolve(null)
return h('div', {}, 'abc')
}
Where we get {value: element, done: true}
, the question then arises should carry over to the first example? i.e render the return value undefined
.
Reference document: the iterator protocol
Yes, I guess that would be a breaking change.
I think rendering undefined
for your first example makes sense.
non-async generators are not affected because of concatenation [element, undefined]
I'm not so much worried about it being a breaking change, but more a semantic divergence. The iterator protocol doesn't establish precedence for consuming the iterator value after the done
signal has been established. Do you have any examples where this is not the case?
From MDN: If value is present alongside done, it is the iterator's return value
I see what you mean
function* x() { yield 1; yield 2; return 3}
for (v of x()) { console.log(v) }
produces
1, 2, undefined
instead of
1, 2, 3
However the docs clearly define return-value behavior, so I would say it's fine. Especially since we are using generators here for control-flow and not to produce results.
I no longer need this functionality (see #113). Feel free to re-open if you still think this would be a valuable change.