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

Replace Future.finally #279

Closed
wants to merge 2 commits into from
Closed

Replace Future.finally #279

wants to merge 2 commits into from

Conversation

Avaq
Copy link
Member

@Avaq Avaq commented Aug 30, 2018

Remove Future.finally and its aliases

The finally function has long been surpassed by Future.hook, and has
several problems:

  1. An undocumented behaviour where it will run and cancel your
    cleanup Future upon cancellation. This once was intended, and
    copied to Future.hook, but then it was decided to be bad behaviour
    and removed from Future.hook. It stuck around in Future.finally.
  2. It doesn't clean up when the Future crashes.
  3. It's not very useful for any other kind of control flow.

Add Future.assume to fill the gap that Future.finally left

I've personally been using Future.finally only to shorten this:

someFuture
  .chain(_ => Future.reject('Kaputt'))
  .chainRej(_ => Future.reject('Kaputt'))

To this:

someFuture.finally(Future.reject('Kaputt'))

Now that finally is gone, I'll replace it by a function which does this
job, and does it better (it works for resolved Futures as well).

The finally function has long been surpassed by Future.hook, and has
several problems:

1. An undocumented behaviour where it will run *and cancel* your
   cleanup Future upon cancellation. This once was intended, and
   copied to Future.hook, but then it was decided to be bad behaviour
   and removed from Future.hook. It stuck around in Future.finally.
2. It doesn't clean up when the Future crashes.
3. It's not very useful for any other kind of control flow.
@codecov
Copy link

codecov bot commented Aug 30, 2018

Codecov Report

Merging #279 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #279   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          48     48           
  Lines         990    985    -5     
  Branches      215    215           
=====================================
- Hits          990    985    -5
Impacted Files Coverage Δ
src/future.mjs 100% <100%> (ø) ⬆️
src/dispatchers/assume.mjs 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db91a2e...17449fa. Read the comment docs.

I've personally been using Future.finally *only* to shorten this:

    someFuture
      .chain(_ => Future.reject('Kaputt'))
      .chainRej(_ => Future.reject('Kaputt'))

To this:

    someFuture.finally(Future.reject('Kaputt'))

Now that finally is gone, I'll replace it by a function which does this
job, and does it better (it works for resolved Futures as well).
@Avaq
Copy link
Member Author

Avaq commented Aug 30, 2018

I'm going to fix the finally semantics instead of removing it entirely.

@Avaq Avaq closed this Aug 30, 2018
@Avaq Avaq deleted the avaq/remove-finally branch August 30, 2018 13:35
@Avaq Avaq mentioned this pull request Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant