-
Notifications
You must be signed in to change notification settings - Fork 2k
Updated select samples to use async/await. #1012
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
Conversation
MylesBorins
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Some nits inline about when to use an async function and about some of the logic that moved around
appengine/analytics/app.js
Outdated
| const GA_TRACKING_ID = process.env.GA_TRACKING_ID; | ||
|
|
||
| function trackEvent(category, action, label, value) { | ||
| async function trackEvent(category, action, label, value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we are not using the await keyword inside the function I don't believe we need to convert it to an async function. We should still be able to await the function if it returns a thenable (e.g. promise)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
| .order('timestamp', {descending: true}) | ||
| .limit(10); | ||
|
|
||
| return datastore.runQuery(query).then(results => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this logic moved somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's moved to the "/" hander function (~Line 73):
function getVisits() {..}
app.get('/', async (req, res, next) => {
...
let results = await getVisits();
let entities = results[0];
let visits = entities.map(
entity => `Time: ${entity.timestamp}, AddrHash: ${entity.userIp}`
);
...
appengine/datastore/app.js
Outdated
| .catch(next); | ||
| try { | ||
| await insertVisit(visit); | ||
| let results = await getVisits(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to use let instead of const here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
ace-n
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once my + @MylesBorins comments are addressed.
appengine/datastore/app.js
Outdated
| * @param {object} visit The visit record to insert. | ||
| */ | ||
| function insertVisit(visit) { | ||
| async function insertVisit(visit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto to @MylesBorins above comment - do we need this async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
appengine/datastore/app.js
Outdated
| * Retrieve the latest 10 visit records from the database. | ||
| */ | ||
| function getVisits() { | ||
| async function getVisits() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
| 'http://metadata.google.internal/computeMetadata/v1/project/project-id'; | ||
|
|
||
| function getProjectId() { | ||
| async function getProjectId() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this async?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
appengine/pubsub/app.standard.yaml
Outdated
| env_variables: | ||
| PUBSUB_TOPIC: YOUR_TOPIC_NAME | ||
| #PUBSUB_TOPIC: YOUR_TOPIC_NAME | ||
| PUBSUB_TOPIC: sample-topic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did/will you update the docs accordingly, if necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
As requested by Steren.