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
f1b05f02
Commit
f1b05f02
authored
Apr 26, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new observer::cancel utility factory
parent
f06f38c6
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
0 deletions
+28
-0
libcaf_core/caf/flow/observer.hpp
libcaf_core/caf/flow/observer.hpp
+28
-0
No files found.
libcaf_core/caf/flow/observer.hpp
View file @
f1b05f02
...
@@ -112,6 +112,9 @@ public:
...
@@ -112,6 +112,9 @@ public:
/// Returns an observer that ignores any of its inputs.
/// Returns an observer that ignores any of its inputs.
static
observer
ignore
();
static
observer
ignore
();
/// Returns an observer that disposes its subscription immediately.
static
observer
cancel
();
private:
private:
intrusive_ptr
<
impl
>
pimpl_
;
intrusive_ptr
<
impl
>
pimpl_
;
};
};
...
@@ -170,6 +173,26 @@ private:
...
@@ -170,6 +173,26 @@ private:
flow
::
subscription
sub_
;
flow
::
subscription
sub_
;
};
};
template
<
class
T
>
class
canceling_observer
:
public
flow
::
observer_impl_base
<
T
>
{
public:
void
on_next
(
const
T
&
)
override
{
// nop
}
void
on_error
(
const
error
&
)
override
{
// nop
}
void
on_complete
()
override
{
// nop
}
void
on_subscribe
(
flow
::
subscription
sub
)
override
{
sub
.
dispose
();
}
};
template
<
class
OnNextSignature
>
template
<
class
OnNextSignature
>
struct
on_next_trait
;
struct
on_next_trait
;
...
@@ -262,6 +285,11 @@ observer<T> observer<T>::ignore() {
...
@@ -262,6 +285,11 @@ observer<T> observer<T>::ignore() {
return
observer
<
T
>
{
make_counted
<
detail
::
ignoring_observer
<
T
>>
()};
return
observer
<
T
>
{
make_counted
<
detail
::
ignoring_observer
<
T
>>
()};
}
}
template
<
class
T
>
observer
<
T
>
observer
<
T
>::
cancel
()
{
return
observer
<
T
>
{
make_counted
<
detail
::
canceling_observer
<
T
>>
()};
}
/// Creates an observer from given callbacks.
/// Creates an observer from given callbacks.
/// @param on_next Callback for handling incoming elements.
/// @param on_next Callback for handling incoming elements.
/// @param on_error Callback for handling an error.
/// @param on_error Callback for handling an error.
...
...
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