Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-context

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-context - npm Package Compare versions

Comparing version 0.4.0 to 0.6.0

37

lib/context.js

@@ -14,4 +14,13 @@ /**

var utils = require('./utils');
/**
* Constants
*/
var COPY_EXCLUDE = {
canceled: true,
deadline: true,
domain: true,
finished: true,
};
/**

@@ -43,6 +52,6 @@ * Context instance.

if (parent) {
parent.once('cancel', function() { self.cancel(); });
parent.once('cancel', function(reason) { self.cancel(reason); });
parent.once('finish', function() { self.end(); });
utils.copyEvent(parent, this);
parent.values(this);

@@ -76,7 +85,7 @@ // reduce deadline to parent's or schedule our own shorter deadline

Context.prototype.cancel = function() {
Context.prototype.cancel = function(reason) {
if (this.canceled || this.finished) return false;
this.canceled = true;
this.emit('cancel');
this.emit('cancel', reason);

@@ -110,2 +119,18 @@ return this.end();

/**
* Return or merges values
*/
Context.prototype.values = function(obj) {
obj = obj || {};
for (var p in this) {
if (this.hasOwnProperty(p) && p[0] !== '_' && !COPY_EXCLUDE[p]) {
obj[p] = this[p];
}
}
return obj;
};
/**
* Schedule timeout

@@ -117,3 +142,3 @@ */

var timeout = function() { self.cancel(); };
var timeout = function() { self.cancel('timeout'); };

@@ -120,0 +145,0 @@ if (self.deadline > now) {

4

package.json
{
"name": "node-context",
"version": "0.4.0",
"version": "0.6.0",
"description": "Context type that carries deadlines, cancelation signals, and other request-scoped values.",

@@ -11,3 +11,3 @@ "main": "lib",

"mocha": "^2.1.0",
"should": "^5.0.1",
"should": "^7.0.2",
"sinon": "^1.12.2"

@@ -14,0 +14,0 @@ },

@@ -74,2 +74,9 @@ # Context [![Build Status](https://travis-ci.org/silas/node-context.png?branch=master)](https://travis-ci.org/silas/node-context)

<a name="context-values"/>
### ctx.values([object])
Return context values.
If `object` is provided then the context values will be merged into it.
## Example

@@ -76,0 +83,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc