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
5namespace 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}
The ArkScript virtual machine.
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:44
Future(ExecutionContext *context, VM *vm, std::vector< Value > &args)
Create a Future and immediately start it through std::async.
Definition Future.cpp:7
const auto Nil
ArkScript Nil value.
Definition VM.hpp:331