Skip to content

Commit

Permalink
Remove cancellation hook from Future.finally
Browse files Browse the repository at this point in the history
To make Future.finally more reliable as a tool which guarantees
execution of the cleanup handler, it would run and cancel the handler
when it would itself be cancelled.

However, this behaviour is subject to some issues:

- The cleanup handler would run when a Future prior to the finally-call
  got cancelled, leading to attempts to dispose yet-to-be-acquired
  resources.
- The cleanup handler would be immediately cancelled, which meant that
  unless it was prepared for ignoring the cancellation signal, cleanup
  wouldn't even happen.

This commit fixes both of those issues by removing this behaviour
altogether. Finally then becomes a function to use solely for cases
where something should happen as a side-effect under rejection and under
resolution of a Future, as its documentation already states.
  • Loading branch information
Avaq committed Aug 30, 2018
1 parent 04c3025 commit bb5406d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/future.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,6 @@ defineBimapperAction('fold', {
});

var finallyAction = {
cancel: function FinallyAction$cancel(){ this.other._interpret(noop, noop, noop)() },
rejected: function FinallyAction$rejected(x){ return this.other._and(new Rejected(x)) },
resolved: function FinallyAction$resolved(x){
return this.other._map(function FoldAction$resolved$mapper(){ return x });
Expand Down
5 changes: 0 additions & 5 deletions test/5.finally.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ var testInstance = function (fin){
setTimeout(done, 25);
});

it('immediately runs and cancels the disposal Future when cancelled early', function (done){
var cancel = fin(F.resolvedSlow, Future(function (){ return function (){ return done() } }))._interpret(done, U.failRej, U.failRes);
setTimeout(cancel, 10);
});

});

};
Expand Down

0 comments on commit bb5406d

Please sign in to comment.