Skip to content

Commit

Permalink
Try to recover from effectful code that is annotated as pure (#173)
Browse files Browse the repository at this point in the history
This puts a try-catch around the bind step in order to try to catch code
that is not expected to have effects but does (by throwing).

While this is clearly a programming error, it is certainly not
implausible that effects creep into FFI code inadvertently for Aff
users. This allows us to be defensive in that case and recover, rather
than have all asynchronous options quitely not work after.

The addition of the try-catch does not seem to have a performance impact
(tested on Node v10.15.3). With and without this change, `pulp test`
takes ~4.8s to run.

There is a discussion around this on #172.
  • Loading branch information
ford-prefect authored and natefaubion committed Aug 15, 2019
1 parent 390857f commit 7f9e362
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Effect/Aff.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,18 @@ var Aff = function () {
switch (status) {
case STEP_BIND:
status = CONTINUE;
step = bhead(step);
if (btail === null) {
bhead = null;
} else {
bhead = btail._1;
btail = btail._2;
try {
step = bhead(step);
if (btail === null) {
bhead = null;
} else {
bhead = btail._1;
btail = btail._2;
}
} catch (e) {
status = RETURN;
fail = util.left(e);
step = null;
}
break;

Expand Down

0 comments on commit 7f9e362

Please sign in to comment.