iopipe.refc

Reference counting using the GC.

The RefCounted struct simply stores the item in a GC block, and also adds a root to that block. Once all known references to the block are removed (tracked by a reference count in the block), then the block is removed, and the destructor run. Since it's a root, it can run the full destructor of the data underneath, without worrying about GC data being collected underneath it.

This depends on the block not being involved in a cycle, which should be fine for iopipes.

Note that atomics are used for the reference count because the GC can destroy things in other threads.

Members

Functions

refCounted
RefCounted!T refCounted(T item)

Return a ref counted version of the given item.

Structs

RefCounted
struct RefCounted(T)

A struct to ensure only one copy of the provided item exists.

Meta