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

Possible wrong examples in doc? #29

Open
acefeel opened this issue Feb 1, 2017 · 1 comment
Open

Possible wrong examples in doc? #29

acefeel opened this issue Feb 1, 2017 · 1 comment

Comments

@acefeel
Copy link

acefeel commented Feb 1, 2017

I tried hours by using the examples, not running at all. Then I find out maybe the example should call send in Discover()'s callback function. Please check.

var Discover = require('node-discover');
var d = Discover(function(){
//this will success.
var success = d.send("someChannel", { message : "oh..." });
});
//outside the callback will cause destination array is undefined inside networks.js:153
// var success = d.send("someChannel", { message : "oh..." });
//also I try to running start() @ this point, it will emit a error "address already bind", cause Discover() already called one, maybe some prevention code should be here to accept multiply start() calls?

@wankdanker
Copy link
Owner

Good catch on two bugs.

To prevent the undefined array in networks.js, we should declare self.destination = []; around line 45. https://github.com/wankdanker/node-discover/blob/master/lib/network.js#L45

There is prevention code to prevent multiple calls to start(), but it's not enough. If you call start() two times
sequentially it will not prevent it because running is set in the callback broadcast.start callback. So, we should track starting or something as well, or just say running=true as early as possible and set it to false if starting the network layer fails.

https://github.com/wankdanker/node-discover/blob/master/lib/discover.js#L246

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

2 participants