Commit b6b46d8e authored by Kenton Varda's avatar Kenton Varda

Apply review comments from @harrishancock.

parent 87c7462d
......@@ -106,6 +106,36 @@ TEST(Memory, Attach) {
KJ_EXPECT(destroyed3 == 3, destroyed3);
}
TEST(Memory, AttachNested) {
uint counter = 0;
uint destroyed1 = 0;
uint destroyed2 = 0;
uint destroyed3 = 0;
auto obj1 = kj::heap<DestructionOrderRecorder>(counter, destroyed1);
auto obj2 = kj::heap<DestructionOrderRecorder>(counter, destroyed2);
auto obj3 = kj::heap<DestructionOrderRecorder>(counter, destroyed3);
auto ptr = obj1.get();
Own<DestructionOrderRecorder> combined = obj1.attach(kj::mv(obj2)).attach(kj::mv(obj3));
KJ_EXPECT(combined.get() == ptr);
KJ_EXPECT(obj1.get() == nullptr);
KJ_EXPECT(obj2.get() == nullptr);
KJ_EXPECT(obj3.get() == nullptr);
KJ_EXPECT(destroyed1 == 0);
KJ_EXPECT(destroyed2 == 0);
KJ_EXPECT(destroyed3 == 0);
combined = nullptr;
KJ_EXPECT(destroyed1 == 1, destroyed1);
KJ_EXPECT(destroyed2 == 2, destroyed2);
KJ_EXPECT(destroyed3 == 3, destroyed3);
}
// TODO(test): More tests.
} // namespace
......
......@@ -155,6 +155,9 @@ public:
// Returns an Own<T> which points to the same object but which also ensures that all values
// passed to `attachments` remain alive until after this object is destroyed. Normally
// `attachments` are other Own<?>s pointing to objects that this one depends on.
//
// Note that attachments will eventually be destroyed in the order they are listed. Hence,
// foo.attach(bar, baz) is equivalent to (but more efficient than) foo.attach(bar).attach(baz).
template <typename U>
Own<U> downcast() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment