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
df975797
Commit
df975797
authored
Apr 26, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add convenience functions for discarding resources
parent
7ea378a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
libcaf_core/caf/async/spsc_buffer.hpp
libcaf_core/caf/async/spsc_buffer.hpp
+15
-1
No files found.
libcaf_core/caf/async/spsc_buffer.hpp
View file @
df975797
...
@@ -329,7 +329,7 @@ struct resource_ctrl : ref_counted {
...
@@ -329,7 +329,7 @@ struct resource_ctrl : ref_counted {
~
resource_ctrl
()
{
~
resource_ctrl
()
{
if
(
buf
)
{
if
(
buf
)
{
if
constexpr
(
IsProducer
)
{
if
constexpr
(
IsProducer
)
{
auto
err
=
make_error
(
sec
::
invalid_upstream
,
auto
err
=
make_error
(
sec
::
disposed
,
"producer_resource destroyed without opening it"
);
"producer_resource destroyed without opening it"
);
buf
->
abort
(
err
);
buf
->
abort
(
err
);
}
else
{
}
else
{
...
@@ -397,11 +397,19 @@ public:
...
@@ -397,11 +397,19 @@ public:
}
}
}
}
/// Convenience function for calling
/// `ctx->make_observable().from_resource(*this)`.
template
<
class
Coordinator
>
template
<
class
Coordinator
>
auto
observe_on
(
Coordinator
*
ctx
)
{
auto
observe_on
(
Coordinator
*
ctx
)
{
return
ctx
->
make_observable
().
from_resource
(
*
this
);
return
ctx
->
make_observable
().
from_resource
(
*
this
);
}
}
/// Calls `try_open` and on success immediately calls `close` on the buffer.
void
close
()
{
if
(
auto
buf
=
try_open
())
buf
->
close
();
}
explicit
operator
bool
()
const
noexcept
{
explicit
operator
bool
()
const
noexcept
{
return
ctrl_
!=
nullptr
;
return
ctrl_
!=
nullptr
;
}
}
...
@@ -454,6 +462,12 @@ public:
...
@@ -454,6 +462,12 @@ public:
}
}
}
}
/// Calls `try_open` and on success immediately calls `cancel` on the buffer.
void
cancel
()
{
if
(
auto
buf
=
try_open
())
buf
->
cancel
();
}
explicit
operator
bool
()
const
noexcept
{
explicit
operator
bool
()
const
noexcept
{
return
ctrl_
!=
nullptr
;
return
ctrl_
!=
nullptr
;
}
}
...
...
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