-
Notifications
You must be signed in to change notification settings - Fork 6
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
May yield* send the last yield value? #3
Comments
I'd rather not see that happen by default given the second case, perhaps a variant of function* g2() {
yield** g1()
}
// Or just a function (which can even be written in userland)
function* g2() {
yield* withInitial(function.sent, g1())
} |
Consider the common use cases (if i can deal with the value of function *g2() {
// function.sent() seems not a proper name, so let's use function.readValue()
const x = function.readValue()
if (i_can_deal_with_it()) {
...
} else { // delegate to sub generator
yield *g1() // g1 can read x via function.readValue()
}
} For the case of previous dark side example, function* service() {
// function.readValue(true) means the value is consumed
// calling function.readValue() again before next next(v) would throw
const token = function.readValue(true)
if (auth(token)) {
yield* serviceOf3rdParty() // so serviceOf3rdParty can't see token
}
}
const serv = service()
serv.next('my-secret-token') |
It makes no sense to be to have it be "consumeable". It's a single static value, like a |
I'm not sure whether "consumable" is good or bad, but it's really consuming values from
It's not like
This is just current semantic, but I think it's not a hard requirement. As I understand, the only core requirement uptonow is providing a way to get the first value sent by
This issue is really about that. |
The essential problem of this issue is, currently function iter() {
return {
[Symbol.iterator]() { return this },
next(v) {
// assume client code never send undefined after first call
if (v === undefined) { // first call,
// do some stuff for setup
} else {
// process
}
}
}
} |
you're right, my mistake - it's more like a live binding, as if from an import.
That's true, but if you design an iterator like that, anyone could break it very easily (including, with |
I'm not sure about that. If a big site had such code (of coz I hope it would never happen), land such change would "break the web" anyway. 😅 |
May it update to
4. Let received be NormalCompletion(LastYieldValue)
so we can satisfy:But allow delegate generator access the last yield value also have dark side:
The text was updated successfully, but these errors were encountered: