Re: [elm-discuss] Outgoing port event ordering

2016-10-17 Thread Kasey Speakman
Or how about adding an incoming subscription port when the localStorage 
save finishes. Then you could put something in the model to indicate you 
are waiting to close. Once the save message comes back, check to see if you 
were waiting to close before sending the close message out the other port.

On Monday, October 17, 2016 at 1:50:18 PM UTC-5, Leroy Campbell wrote:
>
> Ahh...I see. Assuming you have some sort of autosave logic, how about two 
> messages: Save and SaveAndQuit? It seems reasonable to me to split the 
> actions this way...Save could be scheduled using Time.every and 
> SaveAndQuit could be both an explicit user interaction and an incoming 
> port message triggered by window.onbeforeunload().
>
> On Monday, October 17, 2016 at 2:26:20 PM UTC-4, David Andrews wrote:
>>
>> The problem initially arose when I had two ports, one of which wrote to 
>> local storage and the other of which closed the window.  Nothing was ever 
>> written to local storage because the window closed first.  The reason I 
>> went with two ports is because those actions are so conceptually different, 
>> and if it were actually just for local storage I would have used a single 
>> port.  If it were not for the fact that JavaScript processing ceases after 
>> calling window.close, the current port implementation would have worked for 
>> me.
>>
>> On Oct 17, 2016 2:03 PM, "Leroy Campbell"  wrote:
>>
>>> From what I can tell, port communication uses Cmd because interop with 
>>> JavaScript isn't necessarily a request-response communication pattern 
>>> (instead, port are pubsub).
>>>
>>> But I do have a question: *Is the underlying problem a need to 
>>> coordinate access to a shared resource in JavaScript? *I ask because 
>>> you mentioned localStorage in your initial message. I imagine you'd instead 
>>> want to leave the coordination in Elm to take advantage of Elm's 
>>> concurrency model (immutable data + message-passing) and have a single port 
>>> to talk to JavaScript.
>>>
>>> On Monday, October 17, 2016 at 3:03:14 AM UTC-4, David Andrews wrote:

 In another discussion, I was pointed to 
 http://faq.elm-community.org/17.html#what-is-the-difference-between-cmd-and-task,
  
 which sheds some light on the issue, but also raises a few questions.

 Specifically:

1. The article mentions that APIs generally expose Task in favor of 
Cmd. Why is the port API a -> Cmd msg instead of a -> Task Never () 
or something like that?
2. Is there a recommended way to pass data to ports in order? I've 
come up with the workaround of sending over only one port per update 
 and 
using Cmd.Extra.message to trigger additional updates immediately, 
but I don't think it's very clean.


 On Monday, October 17, 2016 at 2:39:01 AM UTC-4, Peter Damoc wrote:
>
> On Mon, Oct 17, 2016 at 8:02 AM, Janis Voigtländer <
> janis.voi...@gmail.com> wrote:
>
>> Peter, the problem in David’s case is that the actions he wants to 
>> order execution of are port data sending, and there is no “something 
>> lower 
>> level, like Tasks” for that. The only API available for port data 
>> sending is Cmd-based.
>>
> Ooops... my bad. I should have looked more carefully. 
>
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>
 -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Elm Discuss" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/elm-discuss/cSzJT2-g8Ss/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> elm-discuss...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-17 Thread Leroy Campbell
Ahh...I see. Assuming you have some sort of autosave logic, how about two 
messages: Save and SaveAndQuit? It seems reasonable to me to split the 
actions this way...Save could be scheduled using Time.every and SaveAndQuit 
could be both an explicit user interaction and an incoming port message 
triggered by window.onbeforeunload().

On Monday, October 17, 2016 at 2:26:20 PM UTC-4, David Andrews wrote:
>
> The problem initially arose when I had two ports, one of which wrote to 
> local storage and the other of which closed the window.  Nothing was ever 
> written to local storage because the window closed first.  The reason I 
> went with two ports is because those actions are so conceptually different, 
> and if it were actually just for local storage I would have used a single 
> port.  If it were not for the fact that JavaScript processing ceases after 
> calling window.close, the current port implementation would have worked for 
> me.
>
> On Oct 17, 2016 2:03 PM, "Leroy Campbell"  > wrote:
>
>> From what I can tell, port communication uses Cmd because interop with 
>> JavaScript isn't necessarily a request-response communication pattern 
>> (instead, port are pubsub).
>>
>> But I do have a question: *Is the underlying problem a need to 
>> coordinate access to a shared resource in JavaScript? *I ask because 
>> you mentioned localStorage in your initial message. I imagine you'd instead 
>> want to leave the coordination in Elm to take advantage of Elm's 
>> concurrency model (immutable data + message-passing) and have a single port 
>> to talk to JavaScript.
>>
>> On Monday, October 17, 2016 at 3:03:14 AM UTC-4, David Andrews wrote:
>>>
>>> In another discussion, I was pointed to 
>>> http://faq.elm-community.org/17.html#what-is-the-difference-between-cmd-and-task,
>>>  
>>> which sheds some light on the issue, but also raises a few questions.
>>>
>>> Specifically:
>>>
>>>1. The article mentions that APIs generally expose Task in favor of 
>>>Cmd. Why is the port API a -> Cmd msg instead of a -> Task Never () 
>>>or something like that?
>>>2. Is there a recommended way to pass data to ports in order? I've 
>>>come up with the workaround of sending over only one port per update and 
>>>using Cmd.Extra.message to trigger additional updates immediately, 
>>>but I don't think it's very clean.
>>>
>>>
>>> On Monday, October 17, 2016 at 2:39:01 AM UTC-4, Peter Damoc wrote:

 On Mon, Oct 17, 2016 at 8:02 AM, Janis Voigtländer <
 janis.voi...@gmail.com> wrote:

> Peter, the problem in David’s case is that the actions he wants to 
> order execution of are port data sending, and there is no “something 
> lower 
> level, like Tasks” for that. The only API available for port data 
> sending is Cmd-based.
>
 Ooops... my bad. I should have looked more carefully. 



 -- 
 There is NO FATE, we are the creators.
 blog: http://damoc.ro/

>>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Elm Discuss" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/elm-discuss/cSzJT2-g8Ss/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> elm-discuss...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-17 Thread David Andrews
The problem initially arose when I had two ports, one of which wrote to
local storage and the other of which closed the window.  Nothing was ever
written to local storage because the window closed first.  The reason I
went with two ports is because those actions are so conceptually different,
and if it were actually just for local storage I would have used a single
port.  If it were not for the fact that JavaScript processing ceases after
calling window.close, the current port implementation would have worked for
me.

On Oct 17, 2016 2:03 PM, "Leroy Campbell"  wrote:

> From what I can tell, port communication uses Cmd because interop with
> JavaScript isn't necessarily a request-response communication pattern
> (instead, port are pubsub).
>
> But I do have a question: *Is the underlying problem a need to coordinate
> access to a shared resource in JavaScript? *I ask because you mentioned
> localStorage in your initial message. I imagine you'd instead want to leave
> the coordination in Elm to take advantage of Elm's concurrency model
> (immutable data + message-passing) and have a single port to talk to
> JavaScript.
>
> On Monday, October 17, 2016 at 3:03:14 AM UTC-4, David Andrews wrote:
>>
>> In another discussion, I was pointed to http://faq.elm-community.or
>> g/17.html#what-is-the-difference-between-cmd-and-task, which sheds some
>> light on the issue, but also raises a few questions.
>>
>> Specifically:
>>
>>1. The article mentions that APIs generally expose Task in favor of
>>Cmd. Why is the port API a -> Cmd msg instead of a -> Task Never ()
>>or something like that?
>>2. Is there a recommended way to pass data to ports in order? I've
>>come up with the workaround of sending over only one port per update and
>>using Cmd.Extra.message to trigger additional updates immediately,
>>but I don't think it's very clean.
>>
>>
>> On Monday, October 17, 2016 at 2:39:01 AM UTC-4, Peter Damoc wrote:
>>>
>>> On Mon, Oct 17, 2016 at 8:02 AM, Janis Voigtländer <
>>> janis.voi...@gmail.com> wrote:
>>>
 Peter, the problem in David’s case is that the actions he wants to
 order execution of are port data sending, and there is no “something lower
 level, like Tasks” for that. The only API available for port data
 sending is Cmd-based.

>>> Ooops... my bad. I should have looked more carefully.
>>>
>>>
>>>
>>> --
>>> There is NO FATE, we are the creators.
>>> blog: http://damoc.ro/
>>>
>> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Elm Discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/elm-discuss/cSzJT2-g8Ss/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-17 Thread Leroy Campbell
>From what I can tell, port communication uses Cmd because interop with 
JavaScript isn't necessarily a request-response communication pattern 
(instead, port are pubsub).

But I do have a question: *Is the underlying problem a need to coordinate 
access to a shared resource in JavaScript? *I ask because you mentioned 
localStorage in your initial message. I imagine you'd instead want to leave 
the coordination in Elm to take advantage of Elm's concurrency model 
(immutable data + message-passing) and have a single port to talk to 
JavaScript.

On Monday, October 17, 2016 at 3:03:14 AM UTC-4, David Andrews wrote:
>
> In another discussion, I was pointed to 
> http://faq.elm-community.org/17.html#what-is-the-difference-between-cmd-and-task,
>  
> which sheds some light on the issue, but also raises a few questions.
>
> Specifically:
>
>1. The article mentions that APIs generally expose Task in favor of Cmd. 
>Why is the port API a -> Cmd msg instead of a -> Task Never () or 
>something like that?
>2. Is there a recommended way to pass data to ports in order? I've 
>come up with the workaround of sending over only one port per update and 
>using Cmd.Extra.message to trigger additional updates immediately, but 
>I don't think it's very clean.
>
>
> On Monday, October 17, 2016 at 2:39:01 AM UTC-4, Peter Damoc wrote:
>>
>> On Mon, Oct 17, 2016 at 8:02 AM, Janis Voigtländer <
>> janis.voi...@gmail.com> wrote:
>>
>>> Peter, the problem in David’s case is that the actions he wants to order 
>>> execution of are port data sending, and there is no “something lower level, 
>>> like Tasks” for that. The only API available for port data sending is 
>>> Cmd-based.
>>>
>> Ooops... my bad. I should have looked more carefully. 
>>
>>
>>
>> -- 
>> There is NO FATE, we are the creators.
>> blog: http://damoc.ro/
>>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-17 Thread David Andrews
In another discussion, I was pointed to 
http://faq.elm-community.org/17.html#what-is-the-difference-between-cmd-and-task,
 
which sheds some light on the issue, but also raises a few questions.

Specifically:

   1. The article mentions that APIs generally expose Task in favor of Cmd. 
   Why is the port API a -> Cmd msg instead of a -> Task Never () or 
   something like that?
   2. Is there a recommended way to pass data to ports in order? I've come 
   up with the workaround of sending over only one port per update and using 
   Cmd.Extra.message to trigger additional updates immediately, but I don't 
   think it's very clean.
   

On Monday, October 17, 2016 at 2:39:01 AM UTC-4, Peter Damoc wrote:
>
> On Mon, Oct 17, 2016 at 8:02 AM, Janis Voigtländer  > wrote:
>
>> Peter, the problem in David’s case is that the actions he wants to order 
>> execution of are port data sending, and there is no “something lower level, 
>> like Tasks” for that. The only API available for port data sending is Cmd
>> -based.
>>
> Ooops... my bad. I should have looked more carefully. 
>
>
>
> -- 
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-17 Thread Peter Damoc
On Mon, Oct 17, 2016 at 8:02 AM, Janis Voigtländer <
janis.voigtlaen...@gmail.com> wrote:

> Peter, the problem in David’s case is that the actions he wants to order
> execution of are port data sending, and there is no “something lower level,
> like Tasks” for that. The only API available for port data sending is Cmd
> -based.
>
Ooops... my bad. I should have looked more carefully.



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-16 Thread Janis Voigtländer
Peter, the problem in David’s case is that the actions he wants to order
execution of are port data sending, and there is no “something lower level,
like Tasks” for that. The only API available for port data sending is Cmd
-based.
​

2016-10-15 23:06 GMT+02:00 Peter Damoc :

> Cmd.batch does not make any guarantee about the order of execution. It is
> use to bundle a batch of commands in one entity.
>
> If you need order of execution, you need to use something lower level,
> like Tasks where you have `andThen`.
>
>
> On Thu, Oct 13, 2016 at 9:59 PM, David Andrews 
> wrote:
>
>> When using Cmd.batch to send data over two ports, the ports receive the
>> events in the same order regardless of the order in which they appear in
>> the batch.  I would expect the events to occur in the order they appear in
>> the batch.
>>
>> Working example: https://daviddta.github.io/elm-port-order-bug/
>> Code: https://github.com/DavidDTA/elm-port-order-bug
>> Looking at the console, we see that port one always receives the event
>> before port two.
>>
>> As some motivation, consider two ports which both write to the same local
>> storage key.  Without a guarantee on the ordering of events, the two
>> subscriptions will race to write the key.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Elm Discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to elm-discuss+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> There is NO FATE, we are the creators.
> blog: http://damoc.ro/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [elm-discuss] Outgoing port event ordering

2016-10-15 Thread Peter Damoc
Cmd.batch does not make any guarantee about the order of execution. It is
use to bundle a batch of commands in one entity.

If you need order of execution, you need to use something lower level, like
Tasks where you have `andThen`.


On Thu, Oct 13, 2016 at 9:59 PM, David Andrews  wrote:

> When using Cmd.batch to send data over two ports, the ports receive the
> events in the same order regardless of the order in which they appear in
> the batch.  I would expect the events to occur in the order they appear in
> the batch.
>
> Working example: https://daviddta.github.io/elm-port-order-bug/
> Code: https://github.com/DavidDTA/elm-port-order-bug
> Looking at the console, we see that port one always receives the event
> before port two.
>
> As some motivation, consider two ports which both write to the same local
> storage key.  Without a guarantee on the ordering of events, the two
> subscriptions will race to write the key.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Elm Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
There is NO FATE, we are the creators.
blog: http://damoc.ro/

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.