Skip to content

Commit

Permalink
docs(samples): updated samples code to use async await (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenqlogic authored and JustinBeckwith committed Nov 23, 2018
1 parent 5aaa74c commit e809288
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions cloud-tasks/createTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* Create a task for a given queue with an arbitrary payload.
*/
function createTask(project, location, queue, options) {
async function createTask(project, location, queue, options) {
// [START cloud_tasks_appengine_create_task]
// [START tasks_quickstart]
// Imports the Google Cloud Tasks library.
Expand Down Expand Up @@ -62,15 +62,10 @@ function createTask(project, location, queue, options) {

console.log('Sending task %j', task);
// Send create task request.
client
.createTask(request)
.then(response => {
const task = response[0].name;
console.log(`Created task ${task}`);
})
.catch(err => {
console.error(`Error in createTask: ${err.message || err}`);
});
const [response] = await client.createTask(request);
const name = response.name;
console.log(`Created task ${name}`);

// [END cloud_tasks_appengine_create_task]
// [END tasks_quickstart]
}
Expand Down Expand Up @@ -122,7 +117,9 @@ const cli = require(`yargs`)
if (module === require.main) {
const opts = cli.help().parse(process.argv.slice(2));
process.env.GCLOUD_PROJECT = opts.project;
createTask(opts.project, opts.location, opts.queue, opts);
createTask(opts.project, opts.location, opts.queue, opts).catch(
console.error
);
}

exports.createTask = createTask;

0 comments on commit e809288

Please sign in to comment.