johnny-five
Version:
The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, pcDuino3, Raspberry Pi, Particle/Spark Core & Photon, Tessel 2, TI Launchpad and more!
23 lines (20 loc) • 433 B
JavaScript
/**
* This atrocity is unfortunately necessary.
* If any other approach can be found, patches
* will gratefully be accepted.
*/
const sleep = {
micro(us) {
const start = process.hrtime();
let waited = 0;
let delta;
while (us > waited) {
delta = process.hrtime(start);
waited = (delta[0] * 1E9 + delta[1]) / 1000;
}
},
milli(ms) {
sleep.micro(ms * 1000);
}
};
module.exports = sleep;