Skip to content
This repository has been archived by the owner on Oct 9, 2021. It is now read-only.

More elaborate errors in callbacks #11

Open
dy opened this issue Jun 24, 2017 · 2 comments
Open

More elaborate errors in callbacks #11

dy opened this issue Jun 24, 2017 · 2 comments

Comments

@dy
Copy link

dy commented Jun 24, 2017

Is there any way to remake mpg123.create((success) => {}) to mpg123.create((err) => {}), with error containing the reason why not able to create?

@jamen
Copy link
Contributor

jamen commented Jun 24, 2017

I do not like the (success) => ... setup either. Funny thing is, none of the functions beside mpg123.write is actually asynchronous. This was just how speaker was setup, so it went in a similar direction here.

My solution in #10 is to return booleans instead of using sync callbacks for every response. So for example:

// Edited
var speaker = mpg123.create()
if (!speaker) {
  throw new Error('Could not open speaker')
}

Throwing errors directly could also be possible!

Personally I like the boolean returns more because it is easier to handle JavaScript from JavaScript. But I get the merits of the other side and I would be open to going that direction too. Let me know what you think. 😄

Edit: I forgot, in the case of mpg123.create, it would return a pointer or false, not only booleans. The same code is possible though.

@dy
Copy link
Author

dy commented Jun 24, 2017

@jamen 👍 for the boolean return, that is common pattern for set.delete, map.delete and others. 👍 for sync API

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants