|
@@ -6,12 +6,6 @@ local util = {}
|
|
|
|
|
|
|
|
util.pack = table.pack or function(...) return { n = select('#', ...), ... } end
|
|
util.pack = table.pack or function(...) return { n = select('#', ...), ... } end
|
|
|
util.unpack = table.unpack or unpack
|
|
util.unpack = table.unpack or unpack
|
|
|
-util.xpcall = function(fn, err, ...)
|
|
|
|
|
- local arg = util.pack(...)
|
|
|
|
|
- return xpcall(function()
|
|
|
|
|
- fn(util.unpack(arg))
|
|
|
|
|
- end, err)
|
|
|
|
|
-end
|
|
|
|
|
util.eq = function(x, y) return x == y end
|
|
util.eq = function(x, y) return x == y end
|
|
|
util.noop = function() end
|
|
util.noop = function() end
|
|
|
util.identity = function(x) return x end
|
|
util.identity = function(x) return x end
|
|
@@ -20,9 +14,11 @@ util.isa = function(object, class)
|
|
|
return type(object) == 'table' and getmetatable(object).__index == class
|
|
return type(object) == 'table' and getmetatable(object).__index == class
|
|
|
end
|
|
end
|
|
|
util.tryWithObserver = function(observer, fn, ...)
|
|
util.tryWithObserver = function(observer, fn, ...)
|
|
|
- return util.xpcall(fn, function(...)
|
|
|
|
|
- return observer:onError(...)
|
|
|
|
|
- end, ...)
|
|
|
|
|
|
|
+ local success, result = pcall(fn, ...)
|
|
|
|
|
+ if not success then
|
|
|
|
|
+ observer:onError(result)
|
|
|
|
|
+ end
|
|
|
|
|
+ return success, result
|
|
|
end
|
|
end
|
|
|
|
|
|
|
|
--- @class Subscription
|
|
--- @class Subscription
|