UNPKG

w1temp

Version:

Measure temperature through DS18B20 sensor connected to 1wire to Raspberry PI with node.js

22 lines (18 loc) 499 B
import fs from 'fs'; export default function fileExistsWait(file, maxMsWait = 20000) { return new Promise((resolve, reject) => { const endTime = +new Date() + maxMsWait; const check = () => { fs.stat(file, (err, stats) => { if (stats && stats.isFile()) { resolve(); } else if (err && err.code === 'ENOENT' && endTime > +new Date()) { setTimeout(check, 1000); } else { reject(); } }); }; check(); }); }