array_stream_set_finalizer: Register an array stream finalizer

View source: R/array-stream.R

array_stream_set_finalizerR Documentation

Register an array stream finalizer

Description

In some cases, R functions that return a nanoarrow_array_stream may require that the scope of some other object outlive that of the array stream. If there is a need for that object to be released deterministically (e.g., to close open files), you can register a function to run after the stream's release callback is invoked from the R thread. Note that this finalizer will not be run if the stream's release callback is invoked from a non-R thread. In this case, the finalizer and its chain of environments will be garbage-collected when nanoarrow:::preserved_empty() is run.

Usage

array_stream_set_finalizer(array_stream, finalizer)

Arguments

array_stream

A nanoarrow_array_stream

finalizer

A function that will be called with zero arguments.

Value

array_stream, invisibly

Examples

stream <- basic_array_stream(list(1:5))
array_stream_set_finalizer(stream, function() message("All done!"))
stream$release()


nanoarrow documentation built on Sept. 30, 2023, 1:06 a.m.