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
How can I dynamically detect a CAF-wrapped generator? #22
Comments
Interesting request... should be pretty easy to add a value to each CAF instance so that they're inspectable. This line is where that instance function is defined... so inserting there a few lines of code to assign a property to the function before returning it should be enough. Something sorta like (untested): function CAF(generatorFn) {
Object.defineProperty(
instance,
"name",
{ value: `CAF:${generatorFn.name || "anonymous"}` }
);
return instance;
// *****************
function instance(tokenOrSignal,...args){
// ..
}
} Then you could inspect them like this: var f = CAF(function *myFunc(){ .. });
var g = CAF(function*(){ .. });
f.name; // CAF:myFunc
g.name; // CAF:anonymous Think that would work? |
Very cool, yep. I'll play with making a PR since I like CAF and this seems like a fun thing to contribute. |
excellent, thanks! :) |
How does this look? #26 I did this for fun more than anything. We use a separate variable to track which pieces of our code use CAF, but it'd be cool if it was built-in. No worries if you think it's unnecessary. |
Thank you for this amazing library. I love being able to cancel async activity.
Example of a legacy and modern function in my codebase:
As we migrate more code to use CAF, I'd like to be able to dynamically inspect values such as these to ensure they're CAF-wrapped functions and not traditional sync functions. I want to do this so that my code can provide better error messages and more intelligence if something is configured wrong between the legacy way (traditional sync) and the modern way (CAF-wrapped generators).
Thanks again for the time you spend maintaining this library. It's really, really awesome. 🙏
The text was updated successfully, but these errors were encountered: