-
-
Save cenuij/99429ad6e3dd84f278239eb0645759ea to your computer and use it in GitHub Desktop.
Remove listener instead of stopping feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nano = require("nano")("http://localhost:5984"); | |
const name = "test"; | |
nano.db.destroy(name, () => { | |
nano.db.create(name, () => { | |
const db = nano.use(name); | |
const feed = db.follow({ since: "now" }, () => {}); | |
// add doc every second | |
const timer = setInterval(() => { | |
db.insert({}, (err, body) => | |
console.log(err ? "ERROR" : "ADD " + body.id) | |
); | |
}, 1000); | |
const handler = change => console.log("GOT " + change.id); | |
// start listener after 5s | |
setTimeout(() => feed.on("change", handler), 5000); | |
// stop listener after 10s | |
setTimeout(() => { | |
feed.removeListener("change", handler); | |
clearInterval(timer); | |
}, 10000); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sort of works but something keeps some reference that prevents the app from exiting normally ...