local Rx = require 'Rx'

local Disposable = Rx.Disposable

local binaryDisposablePrototype = {

    Disposable,
        --superclass

    _first = false,
        -- (Disposable) first disposable

    _second = false,
        -- (Disposable) second disposable

}

--------------------------------------------------------------------------------

function binaryDisposablePrototype:__init(first, second)

    self._first = first
    self._second = second

    return function()

        if not self:isDisposed() then

            local old1 = self._first
            self._first = nil
            if old1 then
                old1:dispose()
            end

            local old2 = self._second
            self._second = nil
            if old2 then
                old2:dispose()
            end
        end

    end

end

--------------------------------------------------------------------------------

return Rx.Class 'Rx.BinaryDisposable'(binaryDisposablePrototype)
