Skip to content
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
rxseger:once
Open

Fix callback reuse when not refreshing#1
rxseger wants to merge 1 commit intoegeback:masterfrom
rxseger:once

Conversation

@rxseger
Copy link
Copy Markdown

@rxseger rxseger commented Oct 7, 2016

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:

      throw new Error("This callback function has already been called by someone else; it can only be called one time.");

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).

rxseger added a commit to rxseger/homebridge-ipmi that referenced this pull request Oct 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant