Closed wle8300 closed 8 years ago
@williamle8300 To stop feedparser, you just stop sending data. You will want to put the timeout around your request (not the parser). Something like this:
var onDoneCalled = false;
var timer;
function onDone (err) {
if (timer) {
clearTimeout(timer);
timer = null;
}
if (!onDoneCalled) {
onDoneCalled = true;
return yourCallback(err);
}
// ignore or maybe log -- but avoid calling your callback more than once
return;
}
timer = setTimeout(function () {
var eTimedOut = new Error("client timed out");
onDone(eTimedOut);
}, 20 * 60 * 1000 /* 20 minutes */);
request( /* ... */).pipe(feedparser).on("end", onDone);
Is there a way to stop feedparser?
Example: I'm parsing an rss source but they have a really slow server. My request is now taking over 20 minutes.
This isn't acceptable to me, so I want to implement a
setTimeout
that will: 1) stop feedparser soend
won't accidentally invoke mycallback
2) invokecallback
with an "client timed out" error