Zolmeister / promiz

A polyfill for ES6-style Promises in 913 bytes (gzip)
MIT License
102 stars 11 forks source link

.done mute errors #6

Closed tunnckoCore closed 10 years ago

tunnckoCore commented 10 years ago
var Promiz = require('promiz');

function testPromise(val) {
    // An example asynchronous promise function
    var deferred = Promiz.defer()
    setTimeout(function(){
        deferred.resolve(val)
    }, 0)
    return deferred
}
testPromise(22).then(function(value){
    // This gets called when the async call finishes

    console.log(value)
    return value
})
.then(function(twentyTwo){
    // Values get passed down the chain. Simple right?
    // Now lets return a promise instead of a value
    throw new Error('some error')

    console.log(twentyTwo)

    return testPromise(twentyTwo+10)
})
.then(function(thiryThree) {
  console.log(thiryThree)
  return testPromise(thiryThree * 3)
})
.then(function(ninetyNine) {
  console.log(ninetyNine)
  return testPromise(ninetyNine);
})
.fail(console.error)
.done(function() {
  console.log('all finally done')
})

Is I miss something? Why when done is called, stop showing the errors?

tunnckoCore commented 10 years ago

Another strange .. :D

// ...
.then(function(twentyTwo){
    // Values get passed down the chain. Simple right?
    // Now lets return a promise instead of a value

    //testPromise(false).reject(new Error('some error'))
    //throw new Error('some error')

    console.log(twentyTwo)

    return testPromise(twentyTwo+10)
})
.then(function(thiryThree) {
  console.log(thiryThree)
  return testPromise(thiryThree * 3)
})
.then(function(ninetyNine) {
  console.log(ninetyNine)
  return testPromise(ninetyNine);
}, console.error)
.done(function() {
  console.log('all finally done')
})

If done is called stops at 33, wtf? Without error.

successfully throw error (handled by last promise, as second arg), and stops at 22 - right place
// ...
.then(function(twentyTwo){
    // Values get passed down the chain. Simple right?
    // Now lets return a promise instead of a value

    //testPromise(false).reject(new Error('some error'))
    throw new Error('some error')

    console.log(twentyTwo)

    return testPromise(twentyTwo+10)
})
.then(function(thiryThree) {
  console.log(thiryThree)
  return testPromise(thiryThree * 3)
})
.then(function(ninetyNine) {
  console.log(ninetyNine)
  return testPromise(ninetyNine);
}, console.error)
tunnckoCore commented 10 years ago

@Zolmeister okey, we have .finish for "finally done" thing - my mistake, but why .done mute errors instead of throw them as docs says?

Zolmeister commented 10 years ago

It does throw them, but only if they exist. In the examples you gave me all errors are handled before the .done() call

tunnckoCore commented 10 years ago

@Zolmeister , looks its no matter - same thing without handling them and only throw new error/reject.

Zolmeister commented 10 years ago

Thanks, fixed

dandv commented 9 years ago

@tunnckoCore: are you still using Promiz? .done was removed with this rewrite.

@Zolmeister: any chance to get .done back? I'm trying to port a project from Q to Promiz.

tunnckoCore commented 9 years ago

@dandv not atm. why you need .done? it's not in the standard. try to not use non standard things.

Zolmeister commented 9 years ago

@dandv Indeed, I would also advise using ES6 Promises

.catch(function(err) {
  setTimeout(function() { throw err })
})