'use strict';

/*
 * o2.js JavaScript Framework (http://o2js.com - info@o2js.com)
 *
 * This program is distributed under the terms of the MIT license.
 * Please see the LICENSE.md file for details.
 */

var privates = require('./privates/core'),
    isPending = privates.isPending,
    enqueue = privates.enqueue,
    handleNext = privates.handleNext;

function Promise(ownerDeferred, DeferredConstructor) {
    this.deferred = ownerDeferred;
    this.Deferred = DeferredConstructor;
}

Promise.prototype.then = function(onFulfilled, onRejected) {
    if (isPending(this)) {
        return enqueue(this, onFulfilled, onRejected);
    }

    return handleNext(this, onFulfilled, onRejected);
};

module.exports = Promise;
