mozilla / node-firefox

node.js modules for interacting with Firefox via the DevTools remote protocol
https://www.npmjs.org/package/firefox
Mozilla Public License 2.0
301 stars 18 forks source link

Proposal for new module: stop-simulator #11

Open sole opened 9 years ago

sole commented 9 years ago

I know it sounds "so simple" but it might hide complexity and prevent platform differences and that IS GOOD.

Right now for stopping a simulator in Mac OS (and Linux I hope) you need to know the process id (PID), then you just use process.kill(pid) to kill the process. If you have enough privileges (i.e. you started it, which is often the case, or have superprivileges) you kill it. Example.

But it is maybe exposing too much of the "internals", and they might also be different in Windows. It might be neat to be able to have this module so you can do things like this:

var startSimulator = require('node-firefox-start-simulator');
var stopSimulator = require('node-firefox-stop-simulator');

startSimulator().then(function(instance) {
  setTimeout(function() {
    stopSimulator(instance).then(function() {
      console.log('ok, stopped');
    });
  }, 1000); 
});

We're not exposing 'pid' at any point! And we get more promises!

tofumatt commented 9 years ago

This is a good idea! I would expect the start-simulator module to have a way to stop things myself, though admittedly your proposal is a better API than what I can think up if it were part of the same module!

I agree, we should have a way to easily stop things too.

-tofumatt On 21 Jan 2015 07:51, "sole" notifications@github.com wrote:

I know it sounds "so simple" but it might hide complexity and prevent platform differences and that IS GOOD.

Right now for stopping a simulator in Mac OS (and Linux I hope) you need to know the process id (PID), then you just use process.kill(pid) to kill the process. If you have enough privileges (i.e. you started it, which is often the case, or have superprivileges) you kill it. Example https://github.com/mozilla/node-firefox-start-simulator/blob/651191860cf06358b059cfab056b5b196238d2f1/examples/startAndListApps.js#L19 .

But it is maybe exposing too much of the "internals", and they might also be different in Windows. It might be neat to be able to have this module so you can do things like this:

var startSimulator = require('node-firefox-start-simulator');var stopSimulator = require('node-firefox-stop-simulator');

startSimulator().then(function(instance) { setTimeout(function() { stopSimulator(instance).then(function() { console.log('ok, stopped'); }); }, 1000); });

We're not exposing 'pid' at any point! And we get more promises!

— Reply to this email directly or view it on GitHub https://github.com/mozilla/node-firefox/issues/11.

nicola commented 9 years ago

For now you can just do something on these lines instance.client.close() process.kill(instance.pid)