Skip to content

Commit

Permalink
feat(thread): add Task finish constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Sep 29, 2024
1 parent 2910005 commit d3ce06a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/include/cubos/core/thread/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ namespace cubos::core::thread
mData = new Data();
}

/// @brief Constructs a finished task.
/// @param value Task result.
/// @return Task.
Task(T value)
: Task{}
{
this->finish(std::move(value));
}

/// @brief Copy constructs.
/// @param other Task.
Task(const Task& other)
Expand Down
7 changes: 7 additions & 0 deletions core/tests/thread/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ using cubos::core::thread::Task;

TEST_CASE("thread::Task")
{
SUBCASE("finished task")
{
Task<int> task{42};
REQUIRE(task.isDone());
REQUIRE(task.result() == 42);
}

SUBCASE("task which produces an int")
{
Task<int> task{};
Expand Down

0 comments on commit d3ce06a

Please sign in to comment.