Skip to content

Commit

Permalink
close #261 - globals.withContext API improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Mar 14, 2015
1 parent 702c37a commit dbb2c15
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ g.runtime || Object.defineProperty(g, 'runtime', {

///
/// * `fn = globals.withContext(fn, cx)`
/// wraps a function so that it executes with context `cx` (or with a new empty context if `cx` is falsy).
/// wraps a function so that it executes with context `cx` (or a wrapper around current context if `cx` is falsy).
/// The previous context will be restored when the function returns (or throws).
/// returns the wrapped function.
g.withContext = function(fn, cx) {
return function() {
var oldContext = g.context;
g.context = cx || {};
g.context = cx || Object.create(oldContext);
try {
return fn.apply(this, arguments)
} finally {
Expand Down
2 changes: 1 addition & 1 deletion lib/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Note: an empty context (`{}`) is automatically set by the server wrappers of the
before they dispatch a request. So, with these wrappers, each request starts with a fresh empty context.

* `fn = globals.withContext(fn, cx)`
wraps a function so that it executes with context `cx` (or with a new empty context if `cx` is falsy).
wraps a function so that it executes with context `cx` (or a wrapper around current context if `cx` is falsy).
The previous context will be restored when the function returns (or throws).
returns the wrapped function.

0 comments on commit dbb2c15

Please sign in to comment.