This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Some hints about the usage of promises #4
Comments
Thanks for the lesson. I'm just starting with JS and node so please be patient. I'm still learning. |
No worries. Promises are very hard to get, if you are new to the js development. Everyone struggles with them. If you have further questions or unsure with some statements, feel free to ask or ping me. |
michbeck100
added a commit
that referenced
this issue
Nov 10, 2015
- change events for dimlevel and switch state are reported back to iOS devices, now
I refactored the plugin according to your comments (8598134), please have a look into the changes. |
Looks good now! Thanks again for creating this great plugin. I think this helps pimatic a lot to get more attraction. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Great work. I like the plugin very much. However, unfortunately I don't have a ios device for testing.
I did spot some errors in the code, I want to point out to improve it a little bit:
You are calling the callback, before the actions finished, because you are passing the result of the callback call to the then handler. You probably call the callback in the then handler:
This parses a function, that calls the callback to the handler. Which is the right way.
Further you should handle errors:
catch catches an error and passes it to the callback. done throws all unhandled errors.
The same problem here. You parsing the result of
device.turnOn()
to the then handler. However you want to pass a function, that calls turnOn:You can even flatten the callback chain here:
As rule of thumb: Always make sure to pass a function
=> ...
to a then handler. Further end each chain of promise class with a.catch( (error) => callback(error) )
, if you want to pass the error to a callback and with.done()
to not silently discard errors.The text was updated successfully, but these errors were encountered: