Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

docs(samples): updated samples code to use async await #139

Merged
merged 3 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions samples/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

'use strict';

function listProjects() {
async function listProjects() {
// [START resource_list_projects]
// Imports the Google Cloud client library
const {Resource} = require('@google-cloud/resource');
Expand All @@ -24,27 +24,25 @@ function listProjects() {
const resource = new Resource();

// Lists all current projects
resource
.getProjects()
.then(results => {
const projects = results[0];
console.log('Projects:');
projects.forEach(project => console.log(project.id));
})
.catch(err => {
console.error('ERROR:', err);
});
const [projects] = await resource.getProjects();
console.log('Projects:');
projects.forEach(project => console.log(project.id));

// [END resource_list_projects]
}

require(`yargs`)
.demand(1)
.command(`list`, `List all current projects.`, {}, listProjects)
.example(`node $0 list`, `Lists all current projects.`)
.wrap(120)
.recommendCommands()
.epilogue(
`For more information, see https://cloud.google.com/resource-manager/docs`
)
.help()
.strict().argv;
async function main() {
require(`yargs`)
.demand(1)
.command(`list`, `List all current projects.`, {}, listProjects)
.example(`node $0 list`, `Lists all current projects.`)
.wrap(120)
.recommendCommands()
.epilogue(
`For more information, see https://cloud.google.com/resource-manager/docs`
)
.help()
.strict().argv;
}

main().catch(console.error);
46 changes: 22 additions & 24 deletions samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@

'use strict';

// [START resource_quickstart]
// Imports the Google Cloud client library
const {Resource} = require('@google-cloud/resource');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const resourceClient = new Resource({
projectId: projectId,
});

// Lists current projects
resourceClient
.getProjects()
.then(results => {
const projects = results[0];

console.log('Projects:');
projects.forEach(project => console.log(project.id));
})
.catch(err => {
console.error('ERROR:', err);
async function main() {
// [START resource_quickstart]
// Imports the Google Cloud client library
const {Resource} = require('@google-cloud/resource');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const resourceClient = new Resource({
projectId: projectId,
});
// [END resource_quickstart]

// Lists current projects
const [projects] = await resourceClient.getProjects();

console.log('Projects:');
projects.forEach(project => console.log(project.id));

// [END resource_quickstart]
}

main().catch(console.error);