mintuz / BB8-Commander

A Node CLI Tool for the Sphero BB8 Robot every loves.
MIT License
71 stars 17 forks source link

"End of script" best practices #18

Closed JBX028 closed 8 years ago

JBX028 commented 8 years ago

Hi,

I created a new plugin in order to blink my BB8. You can pass several parameters (color, delay, iterations) and I have a question on how to properly handle the end of my script. For every existing plugin available here, you have to press ctrl-c to leave the script. I understands that the nature of these plugins is to repeat an action every x seconds and this is to the user to decide to stop it, but in my case and because I will pass the number of times I want my BB8 to blink (parameter "iterations"), what is the best practice to leave the script? What I did, was first to disconnect by bb8 (bb8.disconnect) and then stop the script (process.exit()) within the callback section. What is the difference if I just keep process.exit ? Does at mean next time the connection to the bb8 is going to be quicker because not fully disconnected last time? I tried but I don't see a real difference but I am not sure to understand the logic and the impact between the options to properly ends a script and make my bb8 available for any other scripts that could be run afterward.

Thanks in advance for your help

Sud-Puth commented 8 years ago

@JBX028 I don't have the correct answer to this but I can try to answer it for you. If someone has a better answer please do so.

There is no best practice to leave the script as of now. The bb8.disconnect , disconnects the current connection, also I am assuming this just disconnects the bb8 from the current connection but it will not 'upair' the bb8 or rather it will not put the bb8 to permanent sleep.Look at #17 . Also about process.exit() , that command works when you only send in the action commands like for example, node index.js tweet --hash-tag="bb8" --delay=5000 but when the same is given in commands when the express server is running , for example , node index.js express --port=4000 and then pass the parameters for the command, then it will exit the express process rather than just the script plugin. Hope this made some sense.

P.S. I have a W.I.P that is kind of taking into account some of this issues that I haven't checked in yet but life is taking precedence

JBX028 commented 8 years ago

Thanks a lot for your answer. I will perhaps just keep process.exit() then in order to avoid to unpair the bb8. Again it require more testing. In any case, thanks for this project !

2016-04-07 4:30 GMT+02:00 Sudheer Reddy notifications@github.com:

@JBX028 https://github.com/JBX028 I don't have the correct answer to this but I can try to answer it for you. If someone has a better answer please do so.

There is no best practice to leave the script as of now. The bb8.disconnect , disconnects the current connection, also I am assuming this just disconnects the bb8 from the current connection but it will not 'upair' the bb8 or rather it will not put the bb8 to permanent sleep.Look at #17 https://github.com/mintuz/BB8-Commander/issues/17 . Also about process.exit() , that command works when you only send in the action commands like for example, node index.js tweet --hash-tag="bb8" --delay=5000 but when the same is given in commands when the express server is running , for example , node index.js express --port=4000 and then pass the parameters for the command, then it will exit the express process rather than just the script plugin. Hope this made some sense.

P.S: I have a W.I.P that is kind of taking into account some of this issues that I haven't checked in yet but life is taking precedence

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/mintuz/BB8-Commander/issues/18#issuecomment-206662227