source(file.path(usethis::proj_get(), "vignettes", "_common.R"))

Singleton ensures a class only has one instance, and provide a global point of access to it.

How It Works

  1. Create only one instance of the Singleton class; and
  2. If an instance exists, then serve the same object again.

The main features of Singleton are:

When to Use It

stop("Singletons can be a problem in multi-threaded applications, especially when they manipulate mutable data.")
message("Singletons work well for immutable data, such as reading from some data source, since anything that can’t change isn’t going to run into thread clash problems.")


tidylab/R6P documentation built on Dec. 23, 2024, 9:22 a.m.