Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 01, 2011
@dstarke dstarke fixed leaking of contexts between requests and correctly suspending t…
…he current context at the conclusion of a request
2fe3ae8
Showing with 16 additions and 9 deletions.
  1. +16 −9 lib/jsgi/context.js
View
25 lib/jsgi/context.js
@@ -2,14 +2,21 @@
* Provides the request as the context (across async promises)
*/
var promiseModule = require("promised-io/promise");
+var copy = require("commonjs-utils/copy").copy;
+
exports.SetContext= function(vars, nextApp){
- return function(request){
- try{
- promiseModule.currentContext = request.context = ((typeof vars === 'function') ? vars(request) : vars) || {};
- return nextApp(request);
- }
- finally{
- promiseModule.currentContext = null;
- }
- };
+ return function(request){
+ try{
+ var startingContext = copy(((typeof vars === 'function') ? vars(request) : vars) || {} , {});
+ promiseModule.currentContext = request.context = startingContext;
+ return nextApp(request);
+ } finally{
+ if(promiseModule.currentContext &&
+ promiseModule.currentContext.suspend &&
+ typeof promiseModule.currentContext.suspend == "function"){
+ promiseModule.currentContext.suspend();
+ }
+ promiseModule.currentContext = null;
+ }
+ };
};

No commit comments for this range

Something went wrong with that request. Please try again.