local Rx = require 'Rx'

local AnonymousObservable = Rx.AnonymousObservable
local Observable = Rx.Observable

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

return function(observableFactory)

    return AnonymousObservable(function(observer)

        local success, result = pcall(observableFactory)
        if not success then
            result = Observable.throw(result)
        end

        return result:subscribe(observer)

    end)

end
