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

aa

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aa - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

node_modulesXX/co-chan/examples/chan-co-file-ex.js

157

aa.js
// aa.js - async-await.js
this.aa = function () {
'use strict';
var PromiseThunk = require('promise-thunk');

@@ -47,2 +49,21 @@ var isPromise = PromiseThunk.isPromise;

// Queue
function Queue() {
this.tail = this.head = null;
}
Queue.prototype.push = function push(x) {
if (this.tail)
this.tail = this.tail[1] = [x, null];
else
this.tail = this.head = [x, null];
};
Queue.prototype.shift = function shift() {
if (!this.head) return null;
var x = this.head[0];
this.head = this.head[1];
if (!this.head) this.tail = null;
return x;
};
// nextTickDo(fn)

@@ -53,7 +74,8 @@ var nextTickDo = typeof setImmediate === 'function' ? setImmediate :

var tasks = [];
var tasks = new Queue();
var nextTickProgress = false;
// nextTick(fn, ctx, ...args)
function nextTick(fn, ctx, args) {
// nextTick(fn, ...args)
function nextTick(fn) {
if (typeof fn !== 'function')

@@ -66,8 +88,8 @@ throw new TypeError('fn must be a function');

nextTickProgress = true;
nextTickDo(function () {
var args;
while (args = tasks.shift()) {
var fn = args[0], ctx = args[1];
fn.apply(ctx, slice.call(args, 2));
}
while (args = tasks.shift())
args[0](args[1], args[2], args[3], args[4]);
nextTickProgress = false;

@@ -120,75 +142,74 @@ });

nextTick(doValue, null, ret.value, callback);
nextTick(doValue, ret.value, callback, ctx, args);
}
function doValue(value, callback) {
if (value == null ||
typeof value !== 'object' &&
typeof value !== 'function')
return callback(null, value);
}
if (value instanceof GeneratorFunction)
value = value.apply(ctx, args);
if (value instanceof GeneratorFunctionPrototype || isGenerator(value))
return aa.call(ctx, value)(callback);
function doValue(value, callback, ctx, args) {
if (value == null ||
typeof value !== 'object' &&
typeof value !== 'function')
return callback(null, value);
if (value instanceof PromiseThunk)
return value(callback);
if (value instanceof GeneratorFunction)
value = value.apply(ctx, args);
if (isPromise(value))
return value.then(function (val) { callback(null, val); }, callback);
if ((value && value.constructor === GeneratorFunctionPrototype) || isGenerator(value))
return aa.call(ctx, value)(callback);
// function must be a thunk
if (typeof value === 'function')
return value(callback);
// function must be a thunk
if (typeof value === 'function')
return value(callback);
var called = false;
if (isPromise(value))
return value.then(function (val) { callback(null, val); }, callback);
// array
if (value instanceof Array) {
var n = value.length;
if (n === 0) return callback(null, []);
var arr = Array(n);
value.forEach(function (val, i) {
doValue(val, function (err, val) {
if (err) {
if (!called)
called = true, callback(err);
}
else {
arr[i] = val;
if (--n === 0 && !called)
called = true, callback(null, arr);
}
});
var called = false;
// array
if (value instanceof Array) {
var n = value.length;
if (n === 0) return callback(null, []);
var arr = Array(n);
value.forEach(function (val, i) {
doValue(val, function (err, val) {
if (err) {
if (!called)
called = true, callback(err);
}
else {
arr[i] = val;
if (--n === 0 && !called)
called = true, callback(null, arr);
}
});
} // array
});
} // array
// object
else if (value.constructor === Object) {
var keys = Object.keys(value);
var n = keys.length;
if (n === 0) return callback(null, {});
var obj = {};
keys.forEach(function (key) {
obj[key] = undefined;
doValue(value[key], function (err, val) {
if (err) {
if (!called)
called = true, callback(err);
}
else {
obj[key] = val;
if (--n === 0 && !called)
called = true, callback(null, obj);
}
});
// object
else if (value.constructor === Object) {
var keys = Object.keys(value);
var n = keys.length;
if (n === 0) return callback(null, {});
var obj = {};
keys.forEach(function (key) {
obj[key] = undefined;
doValue(value[key], function (err, val) {
if (err) {
if (!called)
called = true, callback(err);
}
else {
obj[key] = val;
if (--n === 0 && !called)
called = true, callback(null, obj);
}
});
} // object
});
} // object
// other value
else
return callback(null, value);
}
// other value
else
return callback(null, value);
}

@@ -204,3 +225,3 @@

function isGenerator(gtor) {
return gtor instanceof GeneratorFunctionPrototype || !!gtor && gtor.next === 'function';
return !!gtor && (gtor.constructor === GeneratorFunctionPrototype || gtor.next === 'function');
}

@@ -207,0 +228,0 @@

{
"name": "aa",
"version": "0.1.7",
"version": "0.1.8",
"description": "aa - Async-Await. co like library, go like channel, thunkify or promisefy wrap package",

@@ -9,3 +9,7 @@ "main": "aa.js",

},
"devDependencies": {},
"devDependencies": {
"co": ">=4.6.0",
"control-c": ">=0.0.9",
"promise-light": ">=0.1.5"
},
"keywords": [

@@ -12,0 +16,0 @@ "chan",

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