Skip to content

miss tyni example with .then().catch() #118

@maboiteaspam

Description

@maboiteaspam

TLDR; I believe an example like this should be added to the README,

P().then(function (port) { throw 'boom!';}).catch(console.error)

Hi,

I ve decided today to start learning promise, i was still stuck into streams ; 0

I would just like to share with you my little experiment to improve the README.

I wrote some shit like this

var Promise = require('promise');

module.exports = function (port, host) {

  var p =  ((port) && Promise.denodeify(function(then){then(null, port)}) ) || require('get-port');

  return p().then(function (port){
    if (!(port).match(/[^:]+:[^:]+/)) port = host + ':' + port;
    return port;
  })
}

Which bugs in if (!(port).match(/[^:]+:[^:]+/)) port = host + ':' + port; because port is an int, but match belong to String.

Anyway, the fact is the error was caught by the promise, and did not produce any output.

So i was kind of like wtf ?! for a while...

Maybe i misread the README and missed something, but i believe it worth to show somewhere something like

P().then(function (port) { throw 'boom!';}).catch(console.error)

just to let me people come in and fail in a friendly way while learning and developing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions