ArkScript
A small, lisp-inspired, functional scripting language
Ark::internal::Future Class Reference

#include <Future.hpp>

Collaboration diagram for Ark::internal::Future:
[legend]

Public Member Functions

 Future (ExecutionContext *context, VM *vm, std::vector< Value > &args)
 Create a Future and immediately start it through std::async.
 
Value resolve ()
 Await the future, blocking the thread it is run on.
 

Static Public Attributes

static UserType::ControlFuncs ControlFunctions
 

Private Member Functions

void deleteSelfViaVM ()
 

Private Attributes

std::future< Valuem_value
 The actual thread.
 
VMm_vm
 Non-owning pointer.
 

Detailed Description

Definition at line 27 of file Future.hpp.

Constructor & Destructor Documentation

◆ Future()

Ark::internal::Future::Future ( ExecutionContext * context,
VM * vm,
std::vector< Value > & args )

Create a Future and immediately start it through std::async.

Parameters
contexta dedicated context for the future to run on
vmnon owning pointer to the VM
argslist of (function, arguments...) to create the future

Definition at line 20 of file Future.cpp.

References Ark::VM::deleteContext(), m_value, and Ark::VM::resolve().

Member Function Documentation

◆ deleteSelfViaVM()

void Ark::internal::Future::deleteSelfViaVM ( )
private

Definition at line 47 of file Future.cpp.

References Ark::VM::deleteFuture(), and m_vm.

◆ resolve()

Value Ark::internal::Future::resolve ( )

Await the future, blocking the thread it is run on.

Returns
Value Nil if the future is invalid (has already been awaited), otherwise the value

Definition at line 37 of file Future.cpp.

References m_value, and Ark::Nil.

Member Data Documentation

◆ ControlFunctions

UserType::ControlFuncs Ark::internal::Future::ControlFunctions
static
Initial value:
= {
.ostream_func = [](std::ostream& os, const UserType& user) -> std::ostream& {
os << "Future@" << user.data();
return os;
},
.deleter = [](void* data) {
Future* f = static_cast<Future*>(data);
}
}

Definition at line 44 of file Future.hpp.

◆ m_value

std::future<Value> Ark::internal::Future::m_value
private

The actual thread.

Definition at line 47 of file Future.hpp.

Referenced by Future(), and resolve().

◆ m_vm

VM* Ark::internal::Future::m_vm
private

Non-owning pointer.

Definition at line 48 of file Future.hpp.

Referenced by deleteSelfViaVM().


The documentation for this class was generated from the following files: