local Rx = require 'Rx'

local ObservableBase = Rx.ObservableBase
local Scheduler = Rx.Scheduler
local SchedulerArgument = Rx.internals.SchedulerArgument

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

local EmptyObservable = Rx.Class('Rx.internals.EmptyObservable') {

    ObservableBase,
        -- superclass

    _scheduler = false,
        -- (Scheduler)

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

    __init = function(self, scheduler)
        self._scheduler = scheduler
    end,

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

    subscribeCore = function(self, observer)

        local function scheduleItem(scheduler, state)
            state:onCompleted()
        end

        if self._scheduler == Scheduler.immediate() then
            return scheduleItem(nil, observer)
        end

        return self._scheduler:schedule(observer, scheduleItem)

    end,

}

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

return function(scheduler)

    scheduler = SchedulerArgument.validateWithDefault('Rx.Observable.empty',
                                                      'immediate', scheduler)

    return EmptyObservable(scheduler)

end
