What do you call a function which returns a promise?
This is not the start of a joke
In the javascript community I've seen a function that returns a promise called being "thenable" enough times that I think "thenable" when I'm coding. It's a thenable function.
I like this name for a number of reasons:
1) Thenable describes the functional behaviour. If it returns a promise, you can call "then" on it.
2) It's unique. Promises aren't exactly monadic, so monad isn't appropriate. "Async" is more of a super class of functions and doesn't help describe the nature of a Promise. But "thenable" is uniquely Promisely.
3) I also like that it's not repeating Promise everywhere, (Promissory, Promisified, Promise Function, etc.) which is approaching a circular definition IMO. Being able to google one word which has one specific meaning is really nice.
The current answers aren't really correct. The truth of the matter is there is no short clever name for "function that returns a promise" that is in the consensus of the JS community.
The spec doesn't name them in a special way, no documentation of any popular library names them in a special way. The promises specification does not name them in any special way.
From the other hand, if we check the literature branch originating from Liskov and Shrira, they don't, and neither do Bogle nor Zondervan use any term other than "getting a promise" or "getting the future" for it (they do use claim
for extracting the value).
If we check Mark Miller's work he does not use any terms for it either.
In other languages things don't fare better. C# has no special name for methods that return Task
s (its promises). It does have "async functions" for functions that return async/await but that's only a strict subset. No special name in Scala, no special name in Python, no special name in Java and so on. The only thing close was parse's Android API naming their promises' then
callbacks Continuation
but that's hardly meaningful in this context.
If it makes you feel any better - we don't have a name for something that returns an array either.
then
make a valid bind
. More importantly, very few JS developers even know what monads are and even fewer care.async
modifier is added to the language. Right now and probably event then a lot of people consider things like setTimeout
or fs.openFile
to be async functions.To conclude, the people who invented promises, the people who specified them for JavaScript, the people who put that spec in writing, the spec itself, the promise libraries, the libraries written with those and the average user don't have any special name for it.
I think we can stick to A function that returns a promise.
If it makes you feel any better - we don't name "functions that return an int" either :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With