Skip to Content
C++ Reactive Programming
book

C++ Reactive Programming

by Praseed Pai, Peter Abraham
June 2018
Intermediate to advanced
348 pages
8h 45m
English
Packt Publishing
Content preview from C++ Reactive Programming

The Resource Loan pattern

The Loan pattern, as the  name suggest, loans a resource to a function  In the example given below, a file handle is loaned to consumers of the class. It performs following steps:

  1. It creates a resource that you can use (a file handle )
  2. It loans the resource (file handle ) to functions  (lambdas) that will use it
  3. This function is passed by the caller and executed by the resource holder
  4. The resource (file handle ) is closed or destroyed  by the resource holder

The following code implements the Resource Loan pattern for resource management. The pattern helps to avoid resource leakage when writing code:

//----------- ResourceLoan.cpp #include <rxcpp/rx.hpp> using namespace std; ////////////////////////// // implementation ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Functional Programming in C++

Functional Programming in C++

Ivan Cukic

Publisher Resources

ISBN: 9781788629775Supplemental Content