Skip to content

Commit

Permalink
functions/tips: add run region tags (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
grayside authored and fhinkel committed Apr 18, 2019
1 parent 1d98343 commit 807bc30
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions functions/tips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const functionSpecificComputation = heavyComputation;
const fileWideComputation = lightComputation;

// [START functions_tips_scopes]
// [START run_tips_global_scope]
// Global (instance-wide) scope
// This computation runs at instance cold-start
const instanceVar = heavyComputation();
Expand All @@ -47,9 +48,11 @@ exports.scopeDemo = (req, res) => {

res.send(`Per instance: ${instanceVar}, per function: ${functionVar}`);
};
// [END run_tips_global_scope]
// [END functions_tips_scopes]

// [START functions_tips_lazy_globals]
// [START run_tips_global_lazy]
// Always initialized (at cold-start)
const nonLazyGlobal = fileWideComputation();

Expand All @@ -68,6 +71,7 @@ exports.lazyGlobals = (req, res) => {

res.send(`Lazy global: ${lazyGlobal}, non-lazy global: ${nonLazyGlobal}`);
};
// [END run_tips_global_lazy]
// [END functions_tips_lazy_globals]

// [START functions_tips_connection_pooling]
Expand Down

0 comments on commit 807bc30

Please sign in to comment.