Prechádzať zdrojové kódy

Fix issue where errors were being silenced;

bjorn 9 rokov pred
rodič
commit
32349586d2
2 zmenil súbory, kde vykonal 10 pridanie a 18 odobranie
  1. 5 9
      rx.lua
  2. 5 9
      src/util.lua

+ 5 - 9
rx.lua

@@ -6,12 +6,6 @@ local util = {}
 
 util.pack = table.pack or function(...) return { n = select('#', ...), ... } end
 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.noop = function() 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
 end
 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
 
 --- @class Subscription

+ 5 - 9
src/util.lua

@@ -2,12 +2,6 @@ local util = {}
 
 util.pack = table.pack or function(...) return { n = select('#', ...), ... } end
 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.noop = function() end
 util.identity = function(x) return x end
@@ -16,9 +10,11 @@ util.isa = function(object, class)
   return type(object) == 'table' and getmetatable(object).__index == class
 end
 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
 
 return util