Maybe Task not supported on outbound ports?

拟墨画扇 提交于 2020-01-06 04:13:51

问题


I seem to be getting this error

Trying to send an unsupported type through outbound port `projectRequests`

    port projectRequests : Signal (Maybe (Task String ()))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The specific unsupported type is:

   Task.Task String ()

The types of values that can flow through outbound ports include: Ints, Floats, Bools, Strings, Maybes, Lists, Arrays, Tuples, Json.Values, and concrete records.

However this seems to be fine

port orgRequests : Signal (Task String ())

I am confused as to what is going on here.


回答1:


There are two ways you can use a port:

  1. Send data to out to JavaScript, where you write your own handler to deal with it. This is limited to a subset of data that can be easily transformed to JS values.
  2. Send Tasks to the runtime to be scheduled for execution.

In this case you have data (Maybe) wrapped around your Task, so the compiler assumes (wrongly*) that you want to the use the port for purpose #1.

If you want to execute the Tasks wrapped in Justs on the Signal and do nothing on a Nothing on the Signal, you can filter out the Nothing and unwrap the Just with Signal.Extra.filter or Signal.filterMap identity:

port projectRequests : Signal (Maybe (Task String ()))
port projectRequests = Signal.filterMap identity -- and then whatever you had here before

*Can you please report this error message to the error message catalog? This message could be better since it can guess your intentions from the Task being in the type of the data you're trying to send out.



来源:https://stackoverflow.com/questions/31778519/maybe-task-not-supported-on-outbound-ports

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!