Closed aaron-michaux closed 1 year ago
When you say you have declared a friend function for schedule, what exactly does that look like?
You customise the schedule()
operation by providing an overload of tag_invoke(tag_t<schedule>, your_type)
, rahter than schedule(your_type)
.
Hi, thank you for pointing me in the right direction. I spent the morning reading about tag_invoke
. For anybody interested, here are the sources that I found relevant:
tag_invoke
.I'm feeling pretty confident with the tag_invoke
mechanism; however, I cannot figure out the magic key-strokes to make it work with unifex
.
class Scheduler {
public:
constexpr explicit Scheduler(ExecutionContext& context) noexcept : context_(context) {}
constexpr bool operator==(const Scheduler& other) const noexcept;
constexpr bool operator!=(const Scheduler& other) const noexcept;
constexpr SchedulerSender schedule() const noexcept { return {context_}; }
friend SchedulerSender tag_invoke(unifex::tag_t<unifex::schedule>, const Scheduler& self) noexcept {
return self.schedule();
}
private:
ExecutionContext& context_; // not-owned
};
Still getting the same compile error. I found several example uses in the libunifex
source code that look just like what I've written: for example, in unifex/static_thread_pool.hpp
we have unifex::_static_thread_pool::context::scheduler
using the schedule
CPO like so:
friend schedule_sender
tag_invoke(tag_t<schedule>, const scheduler& s) noexcept {
return s.make_sender_();
}
What's going on?
Hi, I figured it out as follows:
I got the working code for the inline_scheduler
, and slowly added/changed it so that it worked as the scheduler I needed. The compiler diagnostics weren't helpful.
I've written my first scheduler, that schedules on a thread-pool. Next, how to schedule grpc
calls.
Thanks.
Going from Eric's presentations, we have the very simple concept for scheduler:
I've got a super bare-bones implementation here:
In my main function:
This fails to compile: gcc12.2.0 tells me that Scheduler doesn't match the Scheduler concept:
But I have a friend function that does just this! I've spent all day trying to build this up from scratch (so that I eventually understand p2300 thoroughly)... what have I done wrong here?
Thanks in advance for your time.