Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1a8b3841
Commit
1a8b3841
authored
Jan 28, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1368
parents
ecf585a7
4f4c3d79
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
3 deletions
+61
-3
libcaf_core/caf/scheduled_actor.hpp
libcaf_core/caf/scheduled_actor.hpp
+41
-0
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+20
-3
No files found.
libcaf_core/caf/scheduled_actor.hpp
View file @
1a8b3841
...
@@ -647,6 +647,32 @@ public:
...
@@ -647,6 +647,32 @@ public:
return
run_scheduled
(
time_point_cast
<
duration_t
>
(
when
),
make_action
(
what
));
return
run_scheduled
(
time_point_cast
<
duration_t
>
(
when
),
make_action
(
what
));
}
}
/// Runs `what` asynchronously at some point after `when`, iff this actor is
/// alive.
/// @param when The local time until the actor waits before invoking the
/// action. Due to scheduling delays, there will always be some
/// additional wait time. Passing the current time or a past time
/// immediately schedules the action for execution.
/// @param what The action to invoke after waiting on the timeout.
/// @returns A @ref disposable that allows the actor to cancel the action.
template
<
class
Duration
,
class
F
>
disposable
run_scheduled_weak
(
std
::
chrono
::
time_point
<
std
::
chrono
::
system_clock
,
Duration
>
when
,
F
what
)
{
using
std
::
chrono
::
time_point_cast
;
return
run_scheduled_weak
(
time_point_cast
<
timespan
>
(
when
),
make_action
(
what
));
}
/// @copydoc run_scheduled_weak
template
<
class
Duration
,
class
F
>
disposable
run_scheduled_weak
(
std
::
chrono
::
time_point
<
actor_clock
::
clock_type
,
Duration
>
when
,
F
what
)
{
using
std
::
chrono
::
time_point_cast
;
using
duration_t
=
actor_clock
::
duration_type
;
return
run_scheduled_weak
(
time_point_cast
<
duration_t
>
(
when
),
make_action
(
what
));
}
/// Runs `what` asynchronously after the `delay`.
/// Runs `what` asynchronously after the `delay`.
/// @param delay Minimum amount of time that actor waits before invoking the
/// @param delay Minimum amount of time that actor waits before invoking the
/// action. Due to scheduling delays, there will always be some
/// action. Due to scheduling delays, there will always be some
...
@@ -659,6 +685,18 @@ public:
...
@@ -659,6 +685,18 @@ public:
return
run_delayed
(
duration_cast
<
timespan
>
(
delay
),
make_action
(
what
));
return
run_delayed
(
duration_cast
<
timespan
>
(
delay
),
make_action
(
what
));
}
}
/// Runs `what` asynchronously after the `delay`, iff this actor is alive.
/// @param delay Minimum amount of time that actor waits before invoking the
/// action. Due to scheduling delays, there will always be some
/// additional wait time.
/// @param what The action to invoke after the delay.
/// @returns A @ref disposable that allows the actor to cancel the action.
template
<
class
Rep
,
class
Period
,
class
F
>
disposable
run_delayed_weak
(
std
::
chrono
::
duration
<
Rep
,
Period
>
delay
,
F
what
)
{
using
std
::
chrono
::
duration_cast
;
return
run_delayed_weak
(
duration_cast
<
timespan
>
(
delay
),
make_action
(
what
));
}
// -- properties -------------------------------------------------------------
// -- properties -------------------------------------------------------------
/// Returns `true` if the actor has a behavior, awaits responses, or
/// Returns `true` if the actor has a behavior, awaits responses, or
...
@@ -744,7 +782,10 @@ private:
...
@@ -744,7 +782,10 @@ private:
disposable
run_scheduled
(
timestamp
when
,
action
what
);
disposable
run_scheduled
(
timestamp
when
,
action
what
);
disposable
run_scheduled
(
actor_clock
::
time_point
when
,
action
what
);
disposable
run_scheduled
(
actor_clock
::
time_point
when
,
action
what
);
disposable
run_scheduled_weak
(
timestamp
when
,
action
what
);
disposable
run_scheduled_weak
(
actor_clock
::
time_point
when
,
action
what
);
disposable
run_delayed
(
timespan
delay
,
action
what
);
disposable
run_delayed
(
timespan
delay
,
action
what
);
disposable
run_delayed_weak
(
timespan
delay
,
action
what
);
// -- caf::flow bindings -----------------------------------------------------
// -- caf::flow bindings -----------------------------------------------------
...
...
libcaf_core/src/scheduled_actor.cpp
View file @
1a8b3841
...
@@ -885,11 +885,28 @@ disposable scheduled_actor::run_scheduled(actor_clock::time_point when,
...
@@ -885,11 +885,28 @@ disposable scheduled_actor::run_scheduled(actor_clock::time_point when,
return
clock
().
schedule
(
when
,
std
::
move
(
what
),
strong_actor_ptr
{
ctrl
()});
return
clock
().
schedule
(
when
,
std
::
move
(
what
),
strong_actor_ptr
{
ctrl
()});
}
}
disposable
scheduled_actor
::
run_delayed
(
timespan
delay
,
action
what
)
{
disposable
scheduled_actor
::
run_scheduled_weak
(
timestamp
when
,
action
what
)
{
CAF_ASSERT
(
what
.
ptr
()
!=
nullptr
);
CAF_LOG_TRACE
(
CAF_ARG
(
when
));
auto
delay
=
when
-
make_timestamp
();
return
run_scheduled_weak
(
clock
().
now
()
+
delay
,
std
::
move
(
what
));
}
disposable
scheduled_actor
::
run_scheduled_weak
(
actor_clock
::
time_point
when
,
action
what
)
{
CAF_ASSERT
(
what
.
ptr
()
!=
nullptr
);
CAF_ASSERT
(
what
.
ptr
()
!=
nullptr
);
CAF_LOG_TRACE
(
CAF_ARG
(
when
));
return
clock
().
schedule
(
when
,
std
::
move
(
what
),
weak_actor_ptr
{
ctrl
()});
}
disposable
scheduled_actor
::
run_delayed
(
timespan
delay
,
action
what
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
delay
));
return
run_scheduled
(
clock
().
now
()
+
delay
,
std
::
move
(
what
));
}
disposable
scheduled_actor
::
run_delayed_weak
(
timespan
delay
,
action
what
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
delay
));
CAF_LOG_TRACE
(
CAF_ARG
(
delay
));
return
clock
().
schedule
(
clock
().
now
()
+
delay
,
std
::
move
(
what
),
return
run_scheduled_weak
(
clock
().
now
()
+
delay
,
std
::
move
(
what
));
strong_actor_ptr
{
ctrl
()});
}
}
// -- caf::flow bindings -------------------------------------------------------
// -- caf::flow bindings -------------------------------------------------------
...
...
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