Add fetch(urls,opts,cb)

This commit is contained in:
Mitra Ardron 2019-04-16 12:22:52 +10:00
parent a0991f07f6
commit bd73dbd2ac

View File

@ -205,6 +205,11 @@ class Transports {
debug("Fetching %o failed on all transports", urls); debug("Fetching %o failed on all transports", urls);
throw new errors.TransportError(errs.map((err)=>err.message).join(', ')); //Throw err with combined messages if none succeed throw new errors.TransportError(errs.map((err)=>err.message).join(', ')); //Throw err with combined messages if none succeed
} }
static fetch(urls, opts={}, cb) { //TODO-API
if (typeof opts === "function") { cb = opts; opts={}; }
const prom = this.p_rawfetch(urls, opts);
if (cb) { prom.then((res)=>{ try { cb(null,res)} catch(err) { debug("Uncaught error in fetch %O",err)}}).catch((err) => cb(err)); } else { return prom; } // Unpromisify pattern v5
}
// Seeding ===== // Seeding =====
// Similar to storing. // Similar to storing.