seed
seed copied to clipboard
Improvements on Orders methods
Hi, since we are about to release 0.7 I would suggest renaming some Orders methods, for clarity and readability and consistently, here is some better names:
send<->send_msgasync_send<->perform_cmd
and I would suggest to add 2 more methods:
send_after(ms, handler)<->async_send(cmds::timeout(ms, handler))stream_every(ms, handler)<->stream(streams::interval(ms, handler))
and not to forget *_with_handle() methods.
Counter-arguments:
send<->send_msgsendmay be confusing - Send msg? Send request? Send notification?
async_send<->perform_cmd- You don't have to send anything - handler can return
Msg,Option<Msg>or nothing.
- You don't have to send anything - handler can return
send_after,send_after_with_handler,stream_every,stream_every_with_handler- Is writing
perform_cmd(cmds::timeout(andstream(streams::interval(so annoying that we want to introduce 4 new public redundant methods? - It's not possible to e.g. map stream / command in
send_after*andstream_every*.
- Is writing
-
send<->send_msgI thinksendconsistent withstreamandnotifynaming in an expected way. actix framework also usesendto send message, users used to the actor system would expect this to send message.sendmay be confusingI don't think it's confusing since
Orderstalk with the runtime using message, so I would expect thatsendtake message.Send request?
I don't think someone would expect
Ordersit to send HTTP request(if that's what you mean?).Send notification?
same goes for notification which have
notify()and notnotify_msg(). -
async_send<->perform_cmdYou don't have to send anything - handler can return Msg, Option<Msg> or nothing.
Here is an alternative names
cmdorasync_cmdif that desired, the point is to make it clear that this method do an async block and try to make it shorter since it's commonly used method.Note that this argument also apply to
streammethod since we can stream nothing (e.g.(),None). -
send_after,stream_everyIs writing
perform_cmd(cmds::timeout(andstream(streams::interval(so annoying that we want to introduce 4 new public redundant methods?Nope, but it's more convenient to write and read
send_after(..)thanperform_cmd(cmds::timeout(..))and this is common thing to do. Although I don't likestream_every_with_handlename.It's not possible to e.g. map stream / command in send_after* and stream_every*.
I'm not sure what you trying to say here. would you elaborate on this.
I'm not sure what you trying to say here. would you elaborate on this.
You can modify cmd / stream after the creation - .stream(streams::interval(1000, || Msg::OnTick).do_something()); - but yeah, it's an edge case.
Nope, but it's more convenient to write and read send_after(..) than perform_cmd(cmds::timeout(..)) and this is common thing to do.
You can say the same about sending HTTP requests, subscribing to UrlChanged, etc. => I would rather see orders.send_request( or order.on_url_changed( as convenient functions because I use them much more often. But I'm afraid that with each added method it will be harder to understand / read the code.
Other opinions? (@TatriX, @rebo, @Ben-PH, @power-fungus, and others)
Personally, I like send_msg and perform_cmd. I agree that they are not too consistent with stream. Instead, I suggest changing that to subscribe instead.
This is an argument of taste. My taste is more close to elm.