Skip to content
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

Allow introspection of CAF-wrapped generators #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aguynamedben
Copy link

Add 2 properties to functions that are CAF-wrapped generators:

  • cafFn.isCAF - true. So the user can detect they're dealing with a
    function that was produced by CAF.
  • cafFn.generatorName - string. The name of the original generator
    function. "anonymous" if the original generator was an anonymous
    generator.

See the tests added in this diff for examples.

Add 2 properties to functions that are CAF-wrapped generators:
* cafFn.isCAF - true. So the user can detect they're dealing with a
  function that was produced by CAF.
* cafFn.generatorName - string. The name of the original generator
  function. "anonymous" if the original generator was an anonymous
  generator.

See the tests added in this diff for examples.
);
Object.defineProperty(
instance,
"generatorName",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of generatorName, what would you think about origName? I'm a little concerned that "generator" is a bit too leaky of a description.


return instance;

function instance(tokenOrSignal,...args){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't change the name property of the function instance, it won't be obvious in console debugging that such a function is CAF-wrapped. it might be easy to miss that fact in your debugging if you don't think to look for the isCAF boolean.

=> true
console.log(namedFn.generatorName)
=> "namedGenerator"
console.log(namedFn.isCAF);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I think you mean anonymousFn.

=> "namedGenerator"
console.log(namedFn.isCAF);
=> true
console.log(namedFn.generatorName)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -28,7 +28,22 @@ module.exports.signalAll = signalAll;


function CAF(generatorFn) {
return function instance(tokenOrSignal,...args){
// allow users to introspect to understand if the function they're dealing
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also apply the same additions/changes to CAG (in cag.js) as we do here.

Could be isCAG instead of isCAF, but then everywhere I think users might have to check isCAF || isCAG. That might get annoying.

Maybe instead, we could change from isCAF to something generic like isCancelable (or something easier to type and not misspell!), and then have another flag that distinguishes CAF vs CAG.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants