ArkScript
A small, lisp-inspired, functional scripting language
Future.hpp
Go to the documentation of this file.
1/**
2 * @file Future.hpp
3 * @author Lex Plateau (lexplt.dev@gmail.com)
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
21{
22 class VM;
23}
24
25namespace Ark::internal
26{
27 class Future
28 {
29 public:
30 /**
31 * @brief Create a Future and immediately start it through std::async
32 * @param context a dedicated context for the future to run on
33 * @param vm non owning pointer to the VM
34 * @param args list of (function, arguments...) to create the future
35 */
36 Future(ExecutionContext* context, VM* vm, std::vector<Value>& args);
37
38 /**
39 * @brief Await the future, blocking the thread it is run on
40 * @return Value Nil if the future is invalid (has already been awaited), otherwise the value
41 */
42 Value resolve();
43
45
46 private:
47 std::future<Value> m_value; ///< The actual thread
48 VM* m_vm; ///< Non-owning pointer
49
50 void deleteSelfViaVM();
51 };
52}
53
54#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:46
std::future< Value > m_value
The actual thread.
Definition Future.hpp:47
VM * m_vm
Non-owning pointer.
Definition Future.hpp:48
static UserType::ControlFuncs ControlFunctions
Definition Future.hpp:44
Value resolve()
Await the future, blocking the thread it is run on.
Definition Future.cpp:37
Future(ExecutionContext *context, VM *vm, std::vector< Value > &args)
Create a Future and immediately start it through std::async.
Definition Future.cpp:20
A structure holding a bunch of pointers to different useful functions related to this usertype.
Definition UserType.hpp:55