File tree Expand file tree Collapse file tree 9 files changed +101
-0
lines changed
Expand file tree Collapse file tree 9 files changed +101
-0
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ if (LIBSCRATCHCPP_USE_LLVM)
7676 include /scratchcpp/dev/compilerconstant.h
7777 include /scratchcpp/dev/executablecode.h
7878 include /scratchcpp/dev/executioncontext.h
79+ include /scratchcpp/dev/promise.h
7980 )
8081
8182 if (LIBSCRATCHCPP_PRINT_LLVM_IR)
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ #include " ../global.h"
6+ #include " ../spimpl.h"
7+
8+ namespace libscratchcpp
9+ {
10+
11+ class PromisePrivate ;
12+
13+ /* ! \brief The Promise class represents the eventual completion of an asynchronous operation. */
14+ class LIBSCRATCHCPP_EXPORT Promise
15+ {
16+ public:
17+ Promise ();
18+ Promise (const Promise &) = delete ;
19+
20+ bool isResolved () const ;
21+ void resolve ();
22+
23+ private:
24+ spimpl::unique_impl_ptr<PromisePrivate> impl;
25+ };
26+
27+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ target_sources(scratchcpp
1212 executioncontext.cpp
1313 executioncontext_p.cpp
1414 executioncontext_p.h
15+ promise.cpp
16+ promise_p.cpp
17+ promise_p.h
1518 internal /icodebuilder.h
1619 internal /icodebuilderfactory.h
1720 internal /codebuilderfactory.cpp
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include < scratchcpp/dev/promise.h>
4+
5+ #include " promise_p.h"
6+
7+ using namespace libscratchcpp ;
8+
9+ /* ! Constructs Promise. */
10+ Promise::Promise () :
11+ impl(spimpl::make_unique_impl<PromisePrivate>())
12+ {
13+ }
14+
15+ /* ! Returns true if the promise is resolved. */
16+ bool Promise::isResolved () const
17+ {
18+ return impl->isResolved ;
19+ }
20+
21+ /* ! Marks the promise as resolved. */
22+ void Promise::resolve ()
23+ {
24+ impl->isResolved = true ;
25+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #include " promise_p.h"
4+
5+ using namespace libscratchcpp ;
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: Apache-2.0
2+
3+ #pragma once
4+
5+ namespace libscratchcpp
6+ {
7+
8+ struct PromisePrivate
9+ {
10+ bool isResolved = false ;
11+ };
12+
13+ } // namespace libscratchcpp
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ add_subdirectory(blocks)
22add_subdirectory (executioncontext)
33add_subdirectory (llvm)
44add_subdirectory (compiler)
5+ add_subdirectory (promise)
Original file line number Diff line number Diff line change 1+ add_executable (
2+ promise_test
3+ promise_test.cpp
4+ )
5+
6+ target_link_libraries (
7+ promise_test
8+ GTest::gtest_main
9+ scratchcpp
10+ )
11+
12+ gtest_discover_tests(promise_test)
Original file line number Diff line number Diff line change 1+ #include < scratchcpp/dev/promise.h>
2+
3+ #include " ../../common.h"
4+
5+ using namespace libscratchcpp ;
6+
7+ TEST (PromiseTest, Resolve)
8+ {
9+ Promise promise;
10+ ASSERT_FALSE (promise.isResolved ());
11+
12+ promise.resolve ();
13+ ASSERT_TRUE (promise.isResolved ());
14+ }
You can’t perform that action at this time.
0 commit comments