0

I have a function

function getDevices() {
    var devices = [];
    /* code that checks lan for devices and pushes to device array */
    /* this is done with an event emitter so its occurs as devices are found */
    setTimeout(5000, function() {/*stop searching for devices*/});
    return devices;
}

How do i get the function get devices to return all the devices after the 5 seconds?

I saw this post: which uses callbacks but it doesn't end up returning the function. Id like to have a global variable that i can assign the result of getDevices() to without having to access the global variable inside the getDevices function

Community
  • 1
  • 1
trivk96
  • 65
  • 2
  • 8
  • Right now, because of async, this function just returns `[]` because it skips all the way to the return – trivk96 Jun 28 '16 at 21:35
  • You're using `setTimeout` incorrectly too. `setTimeout(fn, delay, arg0, arg1, arg2, ...argN)` – Mulan Jun 28 '16 at 21:38

0 Answers0