"use strict";

exports.evaluateDefer = evaluateDefer;

var evaluate = require("./evaluate");

function evaluateDefer(params) {
    if (typeof Promise !== "function") {
        throw new Error("Promise api is not supported.");
    }

    if (params.callback) {
        throw new Error("Use .then part as callback with Promise.");
    }

    return new Promise(function (resolve, reject) {
        params.callback = function (err, res) {
            if (err) {
                return reject(err);
            }

            return resolve(res);
        };

        return evaluate.evaluate(params);
    });
}

"use strict";

exports.evaluateDefer = evaluateDefer;

var evaluate = require("./evaluate");

function evaluateDefer(params) {
    if (typeof Promise !== "function") {
        throw new Error("Promise api is not supported.");
    }

    return new Promise(function (resolve, reject) {
        if (params.callback) {
            return reject("Use .then part as callback with Promise.");
        }

        params.callback = function (err, res) {
            if (err) {
                return reject(err);
            }

            return resolve(res);
        };

        return evaluate.evaluate(params);
    });
}

--- 
+++ 
@@ -9,11 +9,11 @@
         throw new Error("Promise api is not supported.");
     }
 
-    if (params.callback) {
-        throw new Error("Use .then part as callback with Promise.");
-    }
+    return new Promise(function (resolve, reject) {
+        if (params.callback) {
+            return reject("Use .then part as callback with Promise.");
+        }
 
-    return new Promise(function (resolve, reject) {
         params.callback = function (err, res) {
             if (err) {
                 return reject(err);
Throw an exception if callback is defined in $e.

Use .then part as callback when the defer approach is used.
The check is better before creating the promise.
