Should I call Task.await if Task.yield returns {:ok, value}?

I agree with you but:

  • There are two channels. This is not my design and I have to implement it.
  • You cannot send the late reply to the from of the initial call. It is a phoenix controller, after 2500ms it replies to the http request and then it’s gone. That is why there is another channel to send the late reply.

Again I agree.

  1. From your description you seem to be pushing the “late” value via a Phoenix channel.
  2. Meanwhile you are potentially delaying the response inside the controller for up to 2.5 seconds for the result to possibly show up.

2.5 seconds is valuable time wasted in terms of UX - i.e. minimizing time to first meaningful paint.

Given that (1.) is already in place, wouldn’t it make more sense to immediately render the page with the “pending” placeholder from the controller and update it in the browser it as soon as the value is pushed via the Phoenix channel?

Well as you want details, there is no phoenix channel, the other way is to post the response to another website via HTTP.

I am implementing a Slack command that will do some stuff on the Gitlab API. Heavy stuff, so it can take a while, but sometimes it will take half a second to work. This is for other devs and they do not really care about the first meaningful paint :smiley:

Indeed, as I am coding it, I am leaning towards always acknowledging first and always sending the reply through the other way. It is not what is asked though, but it seems that the Slack timeout is too sensitive about network latency.

The exercise was entertaining though.

2 Likes