* Waits for an operation to be completed. Calling this function will block until the operation is finished. * @param {string} projectId - ID or number of the project you want to use. * @param {string} operationString - Operation instance you want to wait in string format.
(projectId, operationString)
| 18 | * @param {string} operationString - Operation instance you want to wait in string format. |
| 19 | */ |
| 20 | function main(projectId, operationString) { |
| 21 | // [START compute_instances_operation_check] |
| 22 | /** |
| 23 | * TODO(developer): Uncomment and replace these variables before running the sample. |
| 24 | */ |
| 25 | // const projectId = 'YOUR_PROJECT_ID'; |
| 26 | // const operationString = 'YOUR_OPERATION_STRING' |
| 27 | |
| 28 | const compute = require('@google-cloud/compute'); |
| 29 | |
| 30 | // Parse stringified operation to the object instance. |
| 31 | let operation = JSON.parse(operationString); |
| 32 | |
| 33 | async function waitForOperation() { |
| 34 | const operationsClient = new compute.ZoneOperationsClient(); |
| 35 | |
| 36 | while (operation.status !== 'DONE') { |
| 37 | [operation] = await operationsClient.wait({ |
| 38 | operation: operation.name, |
| 39 | project: projectId, |
| 40 | zone: operation.zone.split('/').pop(), |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | console.log('Operation finished.'); |
| 45 | } |
| 46 | |
| 47 | waitForOperation(); |
| 48 | // [END compute_instances_operation_check] |
| 49 | } |
| 50 | |
| 51 | main(...process.argv.slice(2)); |
no test coverage detected