Cloud Function Concepts: Function Termination

Signaling function termination in Node

Code sample

Node.js

To authenticate to Cloud Functions, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// Await-ing promises within functions is OK if you don't return anything
await Promise.resolve();

// These will cause background tasks to stop executing immediately
return 1; // OK: returning a value

// These will wait until the related background task finishes
return Promise.resolve(); // OK: returning the promise itself
return await Promise.resolve(); // Same as above
return Promise.reject(); // OK: same behavior as to-be-resolved promises
return await Promise.reject(); // Same as above

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.