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 Internal object to resolve asynchronously a function call in ArkScript
5 * @date 2022-05-28
6 *
7 * @copyright Copyright (c) 2022-2025
8 *
9 */
10
11#ifndef ARK_VM_FUTURE_HPP
12#define ARK_VM_FUTURE_HPP
13
14#include <future>
15#include <vector>
16
17#include <Ark/VM/Value.hpp>
19
20namespace Ark::internal
21{
22 class Future
23 {
24 public:
25 /**
26 * @brief Create a Future and immediately start it through std::async
27 * @param context a dedicated context for the future to run on
28 * @param vm non owning pointer to the VM
29 * @param args list of (function, arguments...) to create the future
30 */
31 Future(ExecutionContext* context, VM* vm, std::vector<Value>& args);
32
33 /**
34 * @brief Await the future, blocking the thread it is ran on
35 * @return Value Nil if the future is invalid (has already been awaited), otherwise the value
36 */
37 Value resolve();
38
39 private:
42 std::future<Value> m_value; ///< The actual thread
43 };
44}
45
46#endif
Keeping track of the internal data needed by the VM.
Default value type handled by the virtual machine.
The ArkScript virtual machine, executing ArkScript bytecode.
Definition VM.hpp:45
ExecutionContext * m_context
Definition Future.hpp:40
std::future< Value > m_value
The actual thread.
Definition Future.hpp:42
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