Skip to content

Commit

Permalink
code refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly-t committed Nov 30, 2015
1 parent f2d5a8c commit 9270bcf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
17 changes: 1 addition & 16 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
//
// Based on: https://www.promisejs.org/generators/#both
function asyncAdapter(generator) {

var func = function () {

return function () {
var g = generator.apply(this, arguments);

function handle(result) {

if (result.done) {
return $p.resolve(result.value);
}

return $p.resolve(result.value)
.then(function (res) {
return handle(g.next(res));
Expand All @@ -29,18 +25,7 @@ function asyncAdapter(generator) {
} catch (ex) {
return $p.reject(ex);
}
};

// re-applying the tagging logic;
if (generator.tag === undefined) {
if (generator.name) {
func.tag = generator.name;
}
} else {
func.tag = generator.tag;
}

return func;
}

var $p;
Expand Down
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ function $extend(ctx, obj) {
return $p.reject("Callback function is required for the " + (isTX ? "transaction." : "task."));
}

if (taskCtx.cb.constructor.name === 'GeneratorFunction') {
taskCtx.cb = $npm.async(taskCtx.cb);
}

if (tag === undefined) {
if (taskCtx.cb.tag !== undefined) {
// use the default tag associated with the task:
Expand All @@ -432,6 +428,10 @@ function $extend(ctx, obj) {
}
}

if (taskCtx.cb.constructor.name === 'GeneratorFunction') {
taskCtx.cb = $npm.async(taskCtx.cb);
}

var tsk = new Task(taskCtx, tag, isTX);

if (taskCtx.db) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-promise",
"version": "2.6.2",
"version": "2.6.3",
"description": "PostgreSQL via promises",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 9270bcf

Please sign in to comment.