-
Notifications
You must be signed in to change notification settings - Fork 126
Open
Description
Decorators would be very useful for function declarations (incl. generator function declarations). I’d either add that feature to the proposal or mention (e.g. in an FAQ section) why it was postponed/dropped. Python’s decorators work for function declarations.
Use case:
/**
* Returns a function that, when called,
* returns a generator object that is immediately
* ready for input via `next()`
*/
function coroutine(generatorFunction) {
return function (...args) {
let generatorObject = generatorFunction(...args);
generatorObject.next();
return generatorObject;
};
}
// Ugly: wrapping
const myCoroutine1 = coroutine(function* () {
console.log(`First input: ${yield}`);
return 'DONE';
});
// Nice: decorator
@coroutine
function* myCoroutine2() {
console.log(`First input: ${yield}`);
return 'DONE';
}
tlrobinson, laurentpayot, finom and kmmbvnrkmmbvnr
Metadata
Metadata
Assignees
Labels
No labels