ArkScript
A small, fast, functional and scripting language for video games
Future.cpp
Go to the documentation of this file.
1
#include <
Ark/VM/Future.hpp
>
2
3
#include <
Ark/VM/VM.hpp
>
4
5
namespace
Ark::internal
6
{
7
Future::Future
(
ExecutionContext
* context,
VM
* vm, std::vector<Value>& args) :
8
m_context(context), m_vm(vm), m_value(std::async(std::launch::async, [vm, context, args]() mutable {
9
return vm->resolve(context, args);
10
}))
11
{}
12
13
Value
Future::resolve()
14
{
15
if
(!m_value.valid())
16
return
Nil
;
17
18
m_value.wait();
19
Value
res = m_value.get();
20
21
m_vm->deleteContext(m_context);
22
m_context =
nullptr
;
23
24
return
res;
25
}
26
}
Future.hpp
VM.hpp
The ArkScript virtual machine.
Ark::VM
The ArkScript virtual machine, executing ArkScript bytecode.
Definition
VM.hpp:44
Ark::Value
Definition
Value.hpp:60
Ark::internal::Future::Future
Future(ExecutionContext *context, VM *vm, std::vector< Value > &args)
Create a Future and immediately start it through std::async.
Definition
Future.cpp:7
Ark::internal
Definition
Builtins.hpp:26
Ark::Nil
const auto Nil
ArkScript Nil value.
Definition
VM.hpp:331
Ark::internal::ExecutionContext
Definition
ExecutionContext.hpp:31
src
arkreactor
VM
Future.cpp
Generated on Wed Jan 15 2025 19:51:44 for ArkScript by
1.12.0