Long running cloud platform operations and node apis

Google Cloud Storage posted on 15th July 2019

Some cloud apis are considered to be 'long running', which means you wont get the result right away. Rather the result is stored and you can retrieve it later. There is an api for doing all that, so you can of course use that. However, many of the Node API libraries have got that complication covered by returning a promise to the result. This article will use the Video Intelligence API as an example.

Starting your long running operation

Lets reduce it to this, where request contains the parameters for the video intelligence annotation request
const operationResult = await doLong(request);


The Api makes it super simple to submit the request and get a promise to the final result
// manage a long running annotation operation
const doLong = async (request) => {
  // its a long running operation
  const [operation] = await viClient.annotateVideo(request);
  console.log ('annotating');
  // when done, retrieve the result
  const [operationResult] = await operation.promise();
  console.log('getting result');
  return operationResult;

  • The api returns an array, the first element of which is the operation object
  • You can extract a promise from the operation object - again its an array, and the first element of it is the result of the long running operation when resolved.


And now you can extract the operation results from that long running promise resolution. Again, it's an array, but you only want the first element.
const [annotations] = operationResult.annotationResults;


Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, All formats are available from O'ReillyAmazon and all good bookshops. You can also read a preview on O'Reilly

If you prefer Video style learning I also have two courses available. also published by O'Reilly.
Google Apps Script for Developers and Google Apps Script for Beginners.