co icon indicating copy to clipboard operation
co copied to clipboard

Is there a way to check one variable is a thunk ?

Open Pana opened this issue 9 years ago • 5 comments

FYI

Pana avatar Mar 11 '15 09:03 Pana

nope.

jonathanong avatar Mar 11 '15 10:03 jonathanong

Well, if you know that foo is a function, and in the source code (foo.toString()) you see that it accepts only a cb (or callback, etc) argument, then you can assume that foo is a thunk. But don't do that.

I think you have an XY Problem, so what is your problem that you want to solve with this?

madbence avatar Apr 02 '15 15:04 madbence

that may help you tunnckoCore/is-async-function, it's not for thunks but for async functions at all. See the examples on readme, see the tests.

I'm open to add more possible variants than cb and callback, but it seems it works for fs and commonly used libs that are async.

Also look make-callback make synchronous function to have callback api always-callback - create async function from sync or remains async if async function is given always-promise - create promise from async or sync function ^ both work for fs, JSON.parse/stringify and etc.

tunnckoCore avatar Jun 05 '15 07:06 tunnckoCore

@tunnckoCore Good job

Pana avatar Jun 05 '15 07:06 Pana

@Pana I dont know, it's pseudo, but works. Tried to not use regexp, for that slice just 150 chars then indexOf. Using regexp was 2x slower.

But yea, thanks! : )

tunnckoCore avatar Jun 05 '15 07:06 tunnckoCore