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 .finally #315

Open
trufae opened this issue Mar 16, 2017 · 5 comments
Open

Add .finally #315

trufae opened this issue Mar 16, 2017 · 5 comments

Comments

@trufae
Copy link

trufae commented Mar 16, 2017

Bluebird already provides the .finally logic which in some situations makes the code cleaner. it will be good if co can have it too.

@kyeotic
Copy link

kyeotic commented Mar 16, 2017

Javascript already has a finally. Just use it

co(function * () {
  try {
   // try to work
  } catch (e) {
  // handle your errors
  } finally {
    // cleanup
  }
})

@luizamboni
Copy link

luizamboni commented Jul 20, 2017

Javascript already has a finally. Just use it

Yes, all of us, know this, but the intend to use a module like co is invert this control...
to can use a finally in a generator without build a other generator method to wrap try, catch and finally

The same logic can be applied from catch too.. "javascript alreay has a catch" then why co need have one ?
Make sense ?

example:

const obj = {
  insertInDb: function*(attrs){
     //without try ...
  }
}

co(obj.insertInDb(attrs)).catch(...).finally(..close connections etc)

@kyeotic
Copy link

kyeotic commented Jul 20, 2017

Co doesn't add a catch either, because you don't need one. You use the js keywords

const obj = {
  insertInDb: function*(attrs){
     //without try ...
  }
}

co(function * () {
  try {
    yield obj.insertInDb(attrs)
  } catch e() {
    ...
  } finally{ 
    ..close connections etc
  }
})

@kyeotic
Copy link

kyeotic commented Jul 20, 2017

The finally in this line

co(obj.insertInDb(attrs)).catch(...).finally(..close connections etc)

Would have to be on the Promise.prototype. co returns Promises.

@vedmant
Copy link

vedmant commented Aug 13, 2017

You can use .then() after .catch() it will work as .finally() https://stackoverflow.com/a/35999141/1753349

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

No branches or pull requests

4 participants