question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Naming convention for Promise.

See original GitHub issue

I’m so confused. In general case, we name the function like ‘verb-what’ like getItem, setQuantity, request, etc.

On case of GET functions, we can guess what type or what kind of values will return.

How about the function which return promise witch will return some other values? Or, a just Promise. How should I name that?

For example, there are a promise which will query the user’s name from database, should the promise name be getName ? or getNamePromise?

In first case(getName), other co-worker could misguess that this function will return name synchronously, so he could directly assign the variables value, like this,

const name = getName();
console.log(name) // Promise {[[PromiseStatus]]: "pending"....}

it doesn’t seem good to add ‘Async’ suffix (getNameAsync). adding prefix ‘promise’ ( promiseGetName ) neither.

promiseGettingName gettingName … hmm…

Any good idea for this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:7

github_iconTop GitHub Comments

17reactions
chardskarthcommented, Aug 14, 2017

I was searching for something like this: A naming convention to let my code readers know instantly that the variable is a promise. How about prepending when?

let fsJetpack = require("fs-jetpack");
let whenCurrentTree = fsJetpack.inspectTreeAsync(contentsPath);

I thought of the word when because of the ff reasons:

  • it sounds like then. a promise standard word
  • in english terms, it should mean ‘when this happens’
7reactions
namsecommented, Apr 22, 2016

Do the verbs, like ‘fetch’ or ‘load’, look like return promise? Because when I use Fetch API, it was ok for name of ‘fetch’ which return promise.

if were, using ‘loadName’ instead ‘getName’ could be a solution, I think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript naming convention for promises? - Stack Overflow
If you are passing promises as callbacks, inside of object methods, then you can happily name them promise or tweetLoading or dataParsing or ......
Read more >
What is your convention for naming promises that you do not ...
So what you'd be getting back from something like getRedditPost(id) would be a promise of a response, not a request, and the name...
Read more >
JavaScript naming convention for promises? - YouTube
JavaScript : JavaScript naming convention for promises ? [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript ...
Read more >
Using promises - JavaScript - MDN Web Docs
A Promise is an object representing the eventual completion or failure of an asynchronous ... This convention has several advantages.
Read more >
What are the variable naming conventions in JavaScript
A letter (alphabet), an underscore (_), or a dollar sign ($) must be the first character in a variable name, any other special...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found