Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
cython-plus
typon
Commits
46e17962
Commit
46e17962
authored
Jul 06, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test program future.cpp
parent
46bcb13c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
0 deletions
+35
-0
rt/test/future.cpp
rt/test/future.cpp
+35
-0
No files found.
rt/test/future.cpp
0 → 100644
View file @
46e17962
#include <typon/typon.hpp>
#include <cstdio>
using
namespace
typon
;
int
fibo
(
int
n
)
{
if
(
n
<
2
)
return
n
;
return
fibo
(
n
-
1
)
+
fibo
(
n
-
2
);
}
Task
<
int
>
producer
(
int
n
)
{
int
value
=
fibo
(
n
);
printf
(
"[%u] producing %d
\n
"
,
Scheduler
::
thread_id
,
value
);
co_return
value
;
}
Task
<
void
>
consumer
()
{
printf
(
"[%u] launching future
\n
"
,
Scheduler
::
thread_id
);
Future
f
=
co_await
future
(
producer
(
20
));
printf
(
"[%u] waiting on future
\n
"
,
Scheduler
::
thread_id
);
int
value
=
co_await
f
.
get
();
printf
(
"[%u] future yielded %d
\n
"
,
Scheduler
::
thread_id
,
value
);
}
Root
root
()
{
co_await
consumer
();
}
int
main
()
{
root
().
call
();
puts
(
"done"
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment