• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 17288906003

28 Aug 2025 07:25AM UTC coverage: 90.403% (+0.7%) from 89.731%
17288906003

push

github

SuperFola
feat(future)!: adding controlfunctions to Future

9 of 10 new or added lines in 4 files covered. (90.0%)

2 existing lines in 1 file now uncovered.

7837 of 8669 relevant lines covered (90.4%)

145560.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/arkreactor/Builtins/Async.cpp
1
#include <Ark/Builtins/Builtins.hpp>
2

3
#include <memory>
4
#include <thread>
5

6
#include <Ark/Constants.hpp>
7
#include <Ark/TypeChecker.hpp>
8
#include <Ark/VM/VM.hpp>
9

10
namespace Ark::internal::Builtins::Async
11
{
12
    /**
13
     * @name async
14
     * @brief Calls a function asynchronously with a given set of arguments
15
     * @details The function is started in a separate context, with no access to the others, preventing any concurrency problems.
16
     * @param func the function to call
17
     * @param args... the arguments of the function
18
     * =begin
19
     * (let foo (fun (a b) (+ a b)))
20
     * (async foo 1 2)
21
     * =end
22
     * @author https://github.com/SuperFola
23
     */
24
    Value async(std::vector<Value>& n, VM* vm)
1✔
25
    {
1✔
26
        if (n.empty() || (n[0].valueType() != ValueType::PageAddr && n[0].valueType() != ValueType::CProc && n[0].valueType() != ValueType::Closure))
1✔
27
            throw types::TypeCheckingError(
2✔
28
                "async", { { types::Contract { { types::Typedef("function", { ValueType::PageAddr, ValueType::CProc, ValueType::Closure }), types::Typedef("args", ValueType::Any, /* is_variadic= */ true) } }, types::Contract { { types::Typedef("function", { ValueType::PageAddr, ValueType::CProc, ValueType::Closure }) } } } }, n);
1✔
29

30
        Future* future = vm->createFuture(n);
×
NEW
31
        return Value(UserType(future, &future->ControlFunctions));
×
32
    }
1✔
33

34
    /**
35
     * @name await
36
     * @brief Blocks until the result becomes available
37
     * @details
38
     * @param future the future to wait for its result to be available
39
     * =begin
40
     * (let foo (fun (a b) (+ a b)))
41
     * (let async-foo (async foo 1 2))
42
     * (print (await async-foo))
43
     * =end
44
     * @author https://github.com/SuperFola
45
     */
46
    Value await(std::vector<Value>& n, VM* vm [[maybe_unused]])
8✔
47
    {
8✔
48
        if (!types::check(n, ValueType::User) || !n[0].usertypeRef().is<Future>())
8✔
49
            throw types::TypeCheckingError("await", { { types::Contract { { types::Typedef("future", ValueType::User) } } } }, n);
1✔
50

51
        auto& f = n[0].usertypeRef().as<Future>();
7✔
52
        Value res = f.resolve();
7✔
53

54
        return res;
7✔
55
    }
8✔
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc