ArkScript
A small, fast, functional and scripting language for video games
Future.hpp
Go to the documentation of this file.
1/**
2 * @file Future.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief
5 * @version 0.1
6 * @date 2022-05-28
7 *
8 * @copyright Copyright (c) 2022-2024
9 *
10 */
11
12#ifndef ARK_VM_FUTURE_HPP
13#define ARK_VM_FUTURE_HPP
14
15#include <future>
16#include <vector>
17
18#include <Ark/VM/Value.hpp>
20
21namespace Ark::internal
22{
23 class Future
24 {
25 public:
26 /**
27 * @brief Create a Future and immediately start it through std::async
28 * @param context a dedicated context for the future to run on
29 * @param vm non owning pointer to the VM
30 * @param args list of (function, arguments...) to create the future
31 */
32 Future(ExecutionContext* context, VM* vm, std::vector<Value>& args);
33
34 /**
35 * @brief Await the future, blocking the thread it is ran on
36 * @return Value Nil if the future is invalid (has already been awaited), otherwise the value
37 */
38 Value resolve();
39
40 private:
43 std::future<Value> m_value; ///< The actual thread
44 };
45}
46
47#endif
Keeping track of the internal data needed by the VM.
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:44
ExecutionContext * m_context
Definition Future.hpp:41
std::future< Value > m_value
The actual thread.
Definition Future.hpp:43
Value resolve()
Await the future, blocking the thread it is ran on.
Definition Future.cpp:13
Future(ExecutionContext *context, VM *vm, std::vector< Value > &args)
Create a Future and immediately start it through std::async.
Definition Future.cpp:7