some generator issues
Neil Mix
nmix at pandora.com
Sun Apr 22 13:56:53 PDT 2007
>>> Other methods rely on
>>> some sort of generator manager (shift the responsibility to the code
>>> handling the generators rather than within them) or using global
>>> generator vars (which would force the generators to be specific
>>> to the
>>> script containing those vars), both of which aren't ideal in the
>>> above
>>> use case.
>>>
>>> I'm unaware of a Python solution to this issue.
>>
>> Hard to standardize an argument; don't want another keyword.
>> Suggestions?
>>
>> /be
>>
>
> I was thinking of adding another property to the arguments object.
> Perhaps, arguments.generator. The value for this property would be
> null
> (or undefined) if the function isn't a generator function.
Something like this would be great. In practice, this particular
suggestion might be a tad unwieldy:
function foo() {
var gen = arguments.generator;
var command = new AsynchCommand();
command.onResult = function(result) {
gen.send(result);
}
command.execute();
var result = yield;
// do something with the result
}
The unwieldy part being that you're required to set
arguments.generator to a local var because otherwise the arguments
object gets masked. But this could be simplified a little if you
could obtain a send() delegate directly from the generator object:
function foo() {
var command = new AsynchCommand();
command.onResult = arguments.generator.delegate();
command.start();
var result = yield;
// do something with the result
}
More information about the Es4-discuss
mailing list