Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception handling to CallbackList.invoke #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/tink/core/Callback.hx
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@ class CallbackList<T> extends SimpleDisposable {
if (destructive)
dispose();

// Invoke all the cells, even if some of them throw exceptions. Another option would be to fail fast,
// but I think it's not nice to let one rogue cell mess things up for all the others.
final errors = [];
var length = cells.length;
for (i in 0...length)
cells[i].invoke(data);
try cells[i].invoke(data) catch (err:Dynamic) errors.push(err);

busy = false;

Expand All @@ -241,6 +244,22 @@ class CallbackList<T> extends SimpleDisposable {
if (queue.length > 0)
queue.shift()();
}

#if debug_tink
#if js
function dump(str) js.Browser.console.error(str);
#elseif sys
function dump(str) Sys.stderr().writeString('${str}\n');
#else
function dump(str) trace(str);
#end
for (i => err in errors) dump('Callback $i barfed: $err');
#end
switch errors.length {
case 0:
case 1: throw errors[0];
case _: throw errors;
}
}
});

Expand Down
Loading