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

Add async function support #24

Closed
wants to merge 2 commits into from
Closed

Add async function support #24

wants to merge 2 commits into from

Conversation

moeen
Copy link

@moeen moeen commented Jun 18, 2018

Add async function detection. #22

@tunnckoCore
Copy link
Contributor

tunnckoCore commented Jun 18, 2018

also, we were thinking about exposing options object as second argument, or something like that, because it's edge case and most may want to know is it genfn or normal (no matter async or not)

right, @jonschlinkert?

@jonschlinkert
Copy link
Owner

also, we were thinking about exposing options object as second argument,

I haven't decided on the best way to handle this. We can't merge this PR though, as it would break a lot of code. I'm leaning towards exposing another method for this.

@ghost
Copy link

ghost commented Sep 25, 2018

Maybe you could add "hooks" support? That would not break existing code and would work great.
Think about this:

kindOf(2);
kindOf.register(function a(b) { if(isAsyncFunction(b)) return `AsyncFunction`; return false; });

Sort of thing, if a hook returns false, the check does not stop.

@ghost
Copy link

ghost commented Sep 25, 2018

I'll submit a PR with the hooks support.

@ghost
Copy link

ghost commented Sep 25, 2018

Boom. See what you think!

return isGeneratorFn(val) ? 'generatorfunction' : 'function';
if (isGeneratorFn(val)) {
return 'generatorfunction'
} else if (isAsyncFn(val)) {
Copy link
Owner

Choose a reason for hiding this comment

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

no need for else if here since the above condition already returns if true. Same with the next condition.

@jonschlinkert
Copy link
Owner

Just because we can, doesn't mean we should -- Ian Malcolm, Jurassic Park

Honestly, after thinking about this more I really don't think this is a good idea. Offhand, I can think of code that would break if we implement this. Everyone would need to start adding multiple conditions to their code.

Instead, I suggest we expose a method, like isAsync or something, so that we can achieve the same end result without changing current behavior.

@tunnckoCore
Copy link
Contributor

Agree.

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

3 participants