Skip to content

Commit

Permalink
lib/entities-store: unref() timers 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Sep 15, 2024
1 parent 430ee35 commit 0861439
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/entities-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,20 @@ const createEntitiesStore = (ttl, now) => {
}

const put = (id, entity) => {
// console.error('put', id, entity) // todo: remove
del(id)

// todo: use sth more memory-efficient than closures?
// todo: set expiry relative to entity's timestamp?
timers.set(id, setTimeout(del, ttl, id))
{
// todo: use sth more memory-efficient than closures?
// todo: set expiry relative to entity's timestamp?
const timer = setTimeout(del, ttl, id)
timers.set(id, timer)
if (timer && timer.unref) {
// allow Node.js to exit by not requiring its event loop to remain active
// note: not available in browsers
timer.unref()
}
}

FeedEntity.verify(entity)
const data = FeedEntity.encode(entity).finish()
Expand Down

0 comments on commit 0861439

Please sign in to comment.