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

promised-io

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promised-io - npm Package Compare versions

Comparing version 0.0.1 to 0.2.2

tests/promise.js

29

engines/node/lib/http-client.js

@@ -39,8 +39,10 @@ /**

request.port = proxySettings.port;
request.host = proxySettings.hostname;
request.protocol = proxySettings.protocol;
request.hostname = proxySettings.hostname;
}
var client = http.createClient(request.port || 80, request.hostname);
var secure = request.protocol.indexOf("s") > -1;
var client = http.createClient(request.port || (secure ? 443 : 80), request.hostname, secure);
var requestPath = request.pathInfo || "";
var requestPath = request.pathname || request.pathInfo || "";
if (request.queryString) {

@@ -50,5 +52,6 @@ requestPath += "?"+request.queryString;

var req = client.request(request.method || "GET", requestPath, request.headers || {host: request.hostname});
var req = client.request(request.method || "GET", requestPath, request.headers || {host: request.host});
var timedOut;
req.addListener("response", function (response){
req.end();
req.on("response", function (response){
if(timedOut){

@@ -70,13 +73,11 @@ return;

});
if(request.encoding){
response.setEncoding(request.encoding);
}
response.setEncoding(request.encoding || "utf8");
response.addListener("data", function (chunk) {
response.on("data", function (chunk) {
sendData(chunk);
});
response.addListener("end", function(){
response.on("end", function(){
bodyDeferred.resolve();
});
response.addListener("error", function(error){
response.on("error", function(error){
bodyDeferred.reject(error);

@@ -91,9 +92,9 @@ });

}, 20000);
req.addListener("error", function(error){
req.on("error", function(error){
deferred.reject(error);
});
req.addListener("timeout", function(error){
req.on("timeout", function(error){
deferred.reject(error);
});
req.addListener("close", function(error){
req.on("close", function(error){
deferred.reject(error);

@@ -100,0 +101,0 @@ });

/*
* Provides time-based promise-returning delay and schedule functions for Rhino
*/
var defer = require("./promise").defer,
LazyArray = require("./lazy-array").LazyArray;
var defer = require("../../../lib/promise").defer,
LazyArray = require("../../../lib/lazy-array").LazyArray;
// returns a promise that is fulfilled after the given number of milliseconds

@@ -7,0 +7,0 @@ exports.delay = function(ms){

var File = require("file"),
LazyArray = require("./lazy-array").LazyArray,
defer = require("./promise").defer;
LazyArray = require("../../../lib/lazy-array").LazyArray,
defer = require("../../../lib/promise").defer;
for(var i in File){
exports[i] = File[i];
}
exports.readFileSync = File.read;

@@ -8,0 +9,0 @@ exports.writeFileSync = File.write;

@@ -8,3 +8,3 @@ /**

// configurable proxy server setting, defaults to http_proxy env var
exports.proxyServer = require("./process").env.http_proxy;
exports.proxyServer = require("../../../lib/process").env.http_proxy;

@@ -11,0 +11,0 @@ exports.request = function(request){

/*
* Provides time-based promise-returning delay and schedule functions
*/
({define:typeof define!="undefined"?define:function(factory){module.exports=factory(require)}}).
define(function(require){
if (typeof system === "object" && system.engine === "rhino"){
// for rhino
return require("../engines/rhino/lib/delay");
}
var defer = require("./promise").defer,
LazyArray = require("./lazy-array").LazyArray;
// returns a promise that is fulfilled after the given number of milliseconds
exports.delay = function(ms){
function delay(ms){
var deferred = defer();

@@ -13,3 +19,3 @@ setTimeout(deferred.resolve, ms);

// returns a lazy array that iterates one every given number of milliseconds
exports.schedule = function(ms){
delay.schedule = function(ms){
var callbacks = [];

@@ -29,1 +35,3 @@ setInterval(function(){

};
return delay.delay = delay;
});

@@ -5,5 +5,5 @@ /**

var fs = require("fs");
if (typeof system === "object" && system.engine === "rhino"){
var fs = require("../engines/rhino/lib/fs");
// for rhino

@@ -15,3 +15,4 @@ for(var i in fs){

else{
var LazyArray = require("./lazy-array").LazyArray,
var fs = require("fs"),
LazyArray = require("./lazy-array").LazyArray,
Buffer = require("buffer").Buffer,

@@ -62,3 +63,16 @@ defer = require("./promise").defer,

if(result){
deferred.resolve();
// if a promise is returned, we wait for it be fulfilled, allows for back-pressure indication
if(result.then){
result.then(function(result){
if(result){
deferred.resolve();
}
else{
readAndSend(fd);
}
}, deferred.reject);
}
else{
deferred.resolve();
}
}else{

@@ -81,4 +95,4 @@ readAndSend(fd);

};
file.write = function(contents, options){
return exports.write(file, contents, options);
file.write = function(contents, options, encoding){
return exports.write(file, contents, options, encoding);
}

@@ -106,4 +120,5 @@ file.close = function(){

var nodeWrite = exports.write;
exports.write = function(path, contents, options){
exports.write = function(path, contents, options, encoding){
if(path instanceof File){
var id = Math.random();
var args = arguments;

@@ -113,3 +128,3 @@ return when(path.fd, function(fd){

if(typeof contents == "string"){
return nodeWrite(fd, contents, options);
return nodeWrite(fd, contents, options, encoding);
}

@@ -169,6 +184,3 @@ return nodeWrite(fd, contents, 0, contents.length, null);

exports.move = exports.rename;
<<<<<<< HEAD
}
=======
}
>>>>>>> 94a58b9edd8296f682cce4140a459ff89c3c6cd3
/**
* HTTP Client using the JSGI standard objects
*/
var defer = require("./promise").defer,
when = require("./promise").when,
print = require("./process").print;
({define:typeof define!="undefined"?define:function(deps, factory){module.exports = factory.apply(this, deps.slice(0,2).map(require))}}).
define(["./promise", "./process", "require"],
function(promise, process, require){
var defer = promise.defer,
when = promise.when,
print = process.print,
request;
if(typeof XMLHttpRequest === "undefined"){
exports.request = require("../engines/node/lib/http-client").request;
request = require("../engines/node/lib/http-client").request;
}
else{
exports.request = function(request){
request = function(request){
var

@@ -62,9 +66,10 @@ scheme = request.scheme || "http",

}
// for back-compat
request.request = request;
// FIXME this way too naive
var isRedirect = exports.isRedirect = function(response){
var isRedirect = request.isRedirect = function(response){
return [301,302,303,307].indexOf(response.status) >= 0;
}
exports.Redirect = function(nextApp, maxRedirects){
request.Redirect = function(nextApp, maxRedirects){
maxRedirects = maxRedirects || 10;

@@ -95,3 +100,3 @@ return function(request){

exports.CookieJar = function(nextApp) {
request.CookieJar = function(nextApp) {
var domainToCookies = {};

@@ -144,8 +149,8 @@

// TODO exports.Cache
// TODO request.Cache
// TODO exports.CookieJar
// TODO request.CookieJar
exports.Client = function(options) {
if (!(this instanceof exports.Client)) return new exports.Client(options);
request.Client = function(options) {
if (!(this instanceof request.Client)) return new request.Client(options);
options = options || {};

@@ -155,7 +160,7 @@ for (var key in options) {

}
this.request = exports.request;
this.request = request;
// turn on redirects by default
var redirects = "redirects" in this ? this.redirects : 20;
if (redirects) {
this.request = exports.CookieJar(exports.Redirect(this.request, typeof redirects === "number" && redirects));
this.request = request.CookieJar(request.Redirect(this.request, typeof redirects === "number" && redirects));
}

@@ -169,1 +174,3 @@

}
return request;
});

@@ -0,3 +1,5 @@

({define:typeof define!="undefined"?define:function(deps, factory){module.exports = factory.apply(this, deps.map(require))}}).
define(["./promise"], function(promise){
try{
var when = require("./promise").when;
var when = promise.when;
}catch(e){

@@ -8,5 +10,7 @@ when = function(value, callback){

}
exports.LazyArray = function(hasSomeAndLength){
function LazyArray(hasSomeAndLength){
return new SomeWrapper(hasSomeAndLength);
};
var exports = LazyArray;
exports.LazyArray = LazyArray;
exports.first = function(array){

@@ -153,1 +157,3 @@ return exports.get(array, 0);

};
return exports;
});

@@ -0,1 +1,3 @@

({define:typeof define!="undefined"?define:function(factory){factory(require,exports)}}).
define(function(require,exports){
if(typeof console !== "undefined"){

@@ -28,1 +30,2 @@ exports.print = function(){

}
});

@@ -0,1 +1,3 @@

(function(define){
define(function(require,exports){

@@ -88,6 +90,23 @@ // Kris Zyp

return this.then(function(value){
return value[propertyName].apply(value, Array.prototype.slice.call(arguments, 1));
return value[functionName].apply(value, Array.prototype.slice.call(arguments, 1));
});
};
/**
* This can be used to conviently resolve a promise with auto-handling of errors:
* setTimeout(deferred.resolverCallback(function(){
* return doSomething();
* }), 100);
*/
Promise.prototype.resolverCallback = function(callback){
var self = this;
return function(){
try{
self.resolve(callback());
}catch(e){
self.reject(e);
}
}
};
/** Dojo/NodeJS methods*/

@@ -181,3 +200,3 @@ Promise.prototype.addCallback = function(callback){

else{
listener.deferred.resolve.apply(listener.deferred, result);
listener.deferred.resolve.call(listener.deferred, result);
}

@@ -322,6 +341,21 @@ }

}
return resolvedCallback(value);
return resolvedCallback ? resolvedCallback(value) : value;
};
/**
* This is convenience function for catching synchronously and asynchronously thrown
* errors. This is used like when() except you execute the initial action in a callback:
* whenCall(function(){
* return doSomethingThatMayReturnAPromise();
* }, successHandler, errorHandler);
*/
exports.whenCall = function(initialCallback, resolvedCallback, rejectCallback, progressCallback){
try{
return exports.when(initialCallback(), resolvedCallback, rejectCallback, progressCallback);
}catch(e){
return rejectCallback(e);
}
}
/**
* Gets the value of a property in a future turn.

@@ -348,5 +382,5 @@ * @param target promise or value for target object

*/
exports.post = function(target, methodName, args){
exports.call = function(target, methodName, args){
return perform(target, function(target){
return target.call(property, args);
return target.call(methodName, args);
},

@@ -434,10 +468,11 @@ function(target){

array.forEach(function(promise, index){
exports.when(promise, each, each);
function each(value){
results[index] = value;
fulfilled++;
if(fulfilled === length){
deferred.resolve(results);
}
}
exports.when(promise,
function(value){
results[index] = value;
fulfilled++;
if(fulfilled === length){
deferred.resolve(results);
}
},
deferred.reject);
});

@@ -449,2 +484,30 @@ }

/**
* Takes a hash of promises and returns a promise that is fulfilled once all
* the promises in the hash keys are fulfilled
* @param hash The hash of promises
* @return the promise that is fulfilled when all the hash keys is fulfilled, resolved to the hash of results
*/
exports.allKeys = function(hash){
var deferred = new Deferred();
var array = Object.keys(hash);
var fulfilled = 0, length = array.length;
var results = {};
if (length === 0) deferred.resolve(results);
else {
array.forEach(function(key){
exports.when(hash[key],
function(value){
results[key] = value;
fulfilled++;
if(fulfilled === length){
deferred.resolve(results);
}
},
deferred.reject);
});
}
return deferred.promise;
};
/**
* Takes an array of promises and returns a promise that is fulfilled when the first

@@ -579,1 +642,3 @@ * promise in the array of promises is fulfilled

};
});
})(typeof define!="undefined"?define:function(factory){factory(require,exports)});
{
"name": "promised-io",
"author": "Kris Zyp",
"dependencies": [],
"contributors": [
"Dean Landolt <dean@deanlandolt.com",
"Nathan Stott <nathan.stott@whiteboard-it.com>"
],
"version": "0.0.1",
"keywords": [
"promise",
"io"
],
"engines": {"node":">=0.1.30", "rhino": true},
"githubName": "promised-io",
"type": "zip",
"location": "http://github.com/kriszyp/promised-io/zipball/master",
"overlay": {
"npm": {
"main": "./lib/fs",
"directories": { "lib": "./lib" }
},
"narwhal": {
"mappings": {
"fs": "../engines/rhino/lib/fs.js"
}
}
}
"name": "promised-io",
"version": "0.2.2",
"author": {
"name": "Kris Zyp"
},
"description": "Promise-based IO",
"licenses": [
{
"type": "AFLv2.1",
"url": "http://trac.dojotoolkit.org/browser/dojo/trunk/LICENSE#L43"
},
{
"type": "BSD",
"url": "http://trac.dojotoolkit.org/browser/dojo/trunk/LICENSE#L13"
}
],
"repository": {
"type":"git",
"url":"http://github.com/kriszyp/promised-io"
},
"contributors": [
"Dean Landolt <dean@deanlandolt.com",
"Nathan Stott <nathan.stott@whiteboard-it.com>"
],
"keywords": [
"promise",
"io"
],
"mappings": {
"patr": "http://github.com/kriszyp/patr/zipball/v0.2.1"
},
"directories": {
"lib": "./lib"
},
"dependencies":{
"patr": ">=0.2.1"
}
}
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