I am wondering about implementation of functionality like the following one.
As an input I receive a function, which could be either synchronous:
externalFunction = () ->
return true
or asynchronous:
externalFunction = (done) ->
done(true)
So, I want to distinguish those types of functions
When I receive a synchronous function, I want to call it and then use its results:
result = externalFunction()
doSomething result
And when I receive an asynchronous one, I want to wait for its callback first:
externalFunction (result) ->
doSomething result
What is the best way to do it?
Right now I'm wondering about something like this:
promise(externalFunction(myCallback)).complete (err) -> ...