Code Monkey home page Code Monkey logo

Comments (18)

toymachiner62 avatar toymachiner62 commented on April 19, 2024 71

Google brought me here, but es6 does support finally https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally.

Should this issue be reopened to add support for .finally?

from axios.

jny986 avatar jny986 commented on April 19, 2024 11

FYI for anyone that comes here in the future .finally() does now work with axios.

from axios.

lzl124631x avatar lzl124631x commented on April 19, 2024 10

@mzabriskie

from axios.

JannieT avatar JannieT commented on April 19, 2024 10

The docs says:

axios.get('/user')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  })
  .then(function () {
    // always executed
  }); 

So I recon "always executed" already works the same as this proposed "finally" or am I missing something?

from axios.

bebraw avatar bebraw commented on April 19, 2024 3

Doesn't that effectively mean that if you want to add finally to axios, then all you need to do it is to shim es6-promise with the aforementioned library? Ie. you would do:

var axios = require('axios');
require('promise.prototype.finally');

...

If so, it's probably better leave it out of the core library and just document that this is possible. That way you don't bloat the current implementation while keeping options open for people that might want the feature.

from axios.

lzl124631x avatar lzl124631x commented on April 19, 2024 2

Suggest adding some comment like similar to finally in other libraries because I was searching for finally and the search didn't bring me to the code snippet. Not everyone necessarily read thru the doc.

from axios.

jeffblake avatar jeffblake commented on April 19, 2024 2

finally has been working fine for me, except (it appears) for Safari Version 10 and 11. I'm seeing

TypeError undefined is not a function (near '...{alert(e)})).finally((function(){e.setSt...')

Do I need to switch to using then, or should I add the polyfill instead?

from axios.

mzabriskie avatar mzabriskie commented on April 19, 2024 1

I'm reluctant to implement this. The ES6 Promise spec doesn't support finally, and I want to be able to drop the polyfill when browsers have native support.

If you feel strongly, or if I'm missing something, please present your argument.

from axios.

mzabriskie avatar mzabriskie commented on April 19, 2024 1

@bebraw yes exactly. The es6-promise polyfill uses the native Promise if it exists. In either case the finally shim will work as you indicated. Let's leave it out of axios and let others add it to their own project if they desire.

I am working on axios today. I can add some documentation about this to the README.

from axios.

marwan2 avatar marwan2 commented on April 19, 2024 1

I have solved this issue, by just include polyfill file from CDN

<script src="https://polyfill.io/v3/polyfill.min.js?features=Promise.prototype.finally" defer></script>

from axios.

kentcdodds avatar kentcdodds commented on April 19, 2024

I found an npm module a few months ago which adds finally support to promises. I don't think this is the one, but it's the only one I found after a minute of searching: https://www.npmjs.com/package/promise.prototype.finally

from axios.

kentcdodds avatar kentcdodds commented on April 19, 2024

well ok then @jmdobry πŸ‘

from axios.

kentcdodds avatar kentcdodds commented on April 19, 2024

I want to be able to drop the polyfill when browsers have native support.

πŸ‘

from axios.

javierfvargas avatar javierfvargas commented on April 19, 2024

The docs says:

axios.get('/user')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  })
  .then(function () {
    // always executed
  }); 

So I recon "always executed" already works the same as this proposed "finally" or am I missing something?

As per the docs that's what I have used. However, I have a question.

What happens if I just want to use the "always executed then" because I don't really care for the reply?.

from axios.

muzi131313 avatar muzi131313 commented on April 19, 2024

after add this ployfill:

const promiseFinally = require('promise.prototype.finally')
promiseFinally.shim()

finally function was added to the Promise.prototype

from axios.

toymachiner62 avatar toymachiner62 commented on April 19, 2024

I see Promise.finally is available in Node 10. Been a while since I tried this, but maybe this just works if you're using Node 10?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/finally

image

from axios.

 avatar commented on April 19, 2024

Not one soul writes the current status here.
The syntax finally is supported in browsers now.
Also axios supports it.

from axios.

 avatar commented on April 19, 2024

march 2020. Finally work in safari + safari mobile

from axios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.