Skip to content

Commit

Permalink
Other: aspromise performance pass
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Apr 24, 2017
1 parent 3f8b74b commit 7445da0
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 68 deletions.
40 changes: 26 additions & 14 deletions dist/light/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/light/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/light/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/light/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/light/protobuf.min.js.map

Large diffs are not rendered by default.

40 changes: 26 additions & 14 deletions dist/minimal/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/minimal/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/minimal/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/minimal/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/minimal/protobuf.min.js.map

Large diffs are not rendered by default.

40 changes: 26 additions & 14 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions lib/aspromise/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,29 @@ module.exports = asPromise;
* @returns {Promise<*>} Promisified function
*/
function asPromise(fn, ctx/*, varargs */) {
var params = [];
for (var i = 2; i < arguments.length;)
params.push(arguments[i++]);
var pending = true;
return new Promise(function asPromiseExecutor(resolve, reject) {
params.push(function asPromiseCallback(err/*, varargs */) {
var params = new Array(arguments.length - 1),
offset = 0,
index = 2,
pending = true;
while (index < arguments.length)
params[offset++] = arguments[index++];
return new Promise(function executor(resolve, reject) {
params[offset] = function callback(err/*, varargs */) {
if (pending) {
pending = false;
if (err)
reject(err);
else {
var args = [];
for (var i = 1; i < arguments.length;)
args.push(arguments[i++]);
resolve.apply(null, args);
var params = new Array(arguments.length - 1),
offset = 0;
while (offset < params.length)
params[offset++] = arguments[offset];
resolve.apply(null, params);
}
}
});
};
try {
fn.apply(ctx || this, params); // eslint-disable-line no-invalid-this
fn.apply(ctx || null, params);
} catch (err) {
if (pending) {
pending = false;
Expand Down
2 changes: 1 addition & 1 deletion lib/aspromise/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@protobufjs/aspromise",
"description": "Returns a promise from a node-style callback function.",
"version": "1.1.1",
"version": "1.1.2",
"author": "Daniel Wirtz <dcode+protobufjs@dcode.io>",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"long": "^3.2.0",
"@protobufjs/aspromise": "^1.1.1",
"@protobufjs/aspromise": "^1.1.2",
"@protobufjs/base64": "^1.1.1",
"@protobufjs/codegen": "^2.0.3",
"@protobufjs/eventemitter": "^1.1.0",
Expand Down

0 comments on commit 7445da0

Please sign in to comment.