我有一个功能
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;
}
如何让功能让设备在5秒后返回所有设备?
我看到了这个post:它使用了回调,但它并没有最终返回该函数。我喜欢有一个全局变量,我可以将getDevices()的结果分配给getDevices函数内的全局变量