Documentation

matlab::cpplib::initMATLABLibraryAsync

Initialize a library of MATLAB function asynchronously

Description

FutureResult<std::shared_ptr<MATLABLib>> initMATLABLibraryAsync(MATLABApplication & application, const std::u16string & ctfPath)

Initialize a library of MATLAB® function asynchronously, to obtain a pointer to a freshly initialized C++ shared library once initialization is complete.

Parameters

MATLABApplication & application

MATLAB Application object returned from initMATLABApplication.

const std::u16string & ctfPath

Name of library. If path is omitted, it is assumed to be in the current folder. For information on how to use ctfPath, see matlab::cpplib::initMATLABLibrary.

Return Value

FutureResult<std::shared_ptr<MATLABLib>>

A std::future from which the status of initialization process, or a library pointer (once initialization is complete) can be obtained.

Exceptions

matlab::cpplib::LibNotFound

No library with the given name found on the shared library path.

matlab::cpplib::LibInitErr

Library cannot be initialized.

Examples

Initialize MATLABLibrary Asynchronously, and Wait Until It Initializes

auto future = mc::initMatlabLibraryAsync(matlabApplication, 
  mc::convertUTF8StringToUTF16String("libdoubleasync.ctf"));
if (!future.valid()) {
    throw std::future_error(std::future_errc::no_state);
}
std::future_status status;
do {
    status = future.wait_for(std::chrono::milliseconds(200));
    if (status == std::future_status::timeout) {
        std::cout << "Library initialization is in progress.\n";
    } else if (status == std::future_status::ready) {
        std::cout << "Library initialization has completed.\n";
    }
    std::this_thread::sleep_for(std::chrono::seconds(1));
} while (status != std::future_status::ready);
auto lib = future.get();

Introduced in R2018a