This repository was archived by the owner on Oct 11, 2023. It is now read-only.
Fix callback reuse when not refreshing#1
Open
rxseger wants to merge 1 commit intoegeback:masterfrom
Open
Conversation
rxseger
added a commit
to rxseger/homebridge-ipmi
that referenced
this pull request
Oct 7, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When getSensors is called after data is already available (i.e., a second time), with !refreshdata, it will call the callback twice: with the old data, and new data. This double-callback causes issues when integrating with other code expecting callbacks to be called only once (Node.js convention):
http://joseoncode.com/2013/12/27/case-of-double-callbacks/
http://stackoverflow.com/questions/16764160/node-js-callback-called-twice
etc.
or in my case, from https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/util/once.js:
took a while to track down node-ipmi was calling it twice and not my code. Not sure of a proper fix but returning with the cached data is one possible fix for only calling it once (and the caller can always pass refreshdata true to get the latest data).