Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't pass async reads to HTTP Response #18

Open
webxl opened this issue Oct 26, 2016 · 0 comments
Open

Doesn't pass async reads to HTTP Response #18

webxl opened this issue Oct 26, 2016 · 0 comments

Comments

@webxl
Copy link

webxl commented Oct 26, 2016

According to node-red/node-red#714 (comment), the original msg object needs to be modified and sent back for it to work. Not sure if this is the best fix (using .once() in the input event handler), but I got beanTemp.js working properly like this:

        // respond to inputs....
        this.on('input', function (msg) {
          if (this.beanConfig && this.beanConfig.device){

            this.beanConfig.device.once('temp', function(temp, valid){
              msg.topic = "temp";
              msg.payload = (temp);
              this.send(msg);
            }.bind(this));

            this.beanConfig.requestTemp();  
          } else {
            this.error('Bean not connected');
            this.send(msg);
          }
        });

        // this.beanConfig.on("connected", function() {
        //     this.beanConfig.device.on('temp', tempDataReceived);
        // }.bind(this));

At first I tried a persistent msg variable in the closure that tempDataReceived could access, but that could lead to race conditions I think. See
https://node-red.slack.com/archives/general/p1476118415001635

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

No branches or pull requests

1 participant