Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk) Add the
LinkedChunkUpdates::peek
.
This patch adds the `LinkedChunkUpdates::peek` method. This is a new channel to read the updates without consuming them, like `LinkedChunkUpdates::take` does. The complexity is: when do we clear/drop the updates then? We don't want to keep them in memory forever. Initially `take` was clearing the updates, but now that we can read them with `peek` too, who's responsible to clear them? Enter `garbage_collect`. First off, we already need to maintain 2 index, resp. `last_taken_index` and `last_peeked_index` so that `take` and `peek` don't return already returned updates. They respectively know the index of the last update that has been read. We can use this information to know which updates must be garbage collected: that's all updates below the two index. Tadaa. Simple. The only _drawback_ (if it can be considered as such) is that the garbage collection happens on the next call to `take` or `peek` (because of the borrow checker). That's not really a big deal in practise. We could make it happens immediately when calling `take` or `peek` but it needs more pointer arithmetic and a less straighforward code.
- Loading branch information