Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support timeout option #8

Merged
merged 3 commits into from Aug 21, 2018
Merged

Support timeout option #8

merged 3 commits into from Aug 21, 2018

Conversation

mgreystone
Copy link
Member

Add a new sendWithOptions function that accepts a timeout option. Reject with an error action if send does not resolve before the timeout.

This is intended to trigger an error when we expect an action from a socket but it never occurs, possibly because the service is down or there is a version mismatch between frontend & backend.

client/index.js Outdated
sent = sent.bimap(cleanup, cleanup)
}

sent.fork(reject, resolve)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilsoft This feels rather clunky to me, & i'm sure i missed something. I'm particularly worried that i'm not handling cancelled asyncs correctly.

Copy link

@rpearce rpearce Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relevant/tangential/helpful reading on this sort of thing: https://mostly-adequate.gitbooks.io/mostly-adequate-guide/ch08.html#asynchronous-tasks

Copy link

@rpearce rpearce Jun 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reading the docs, I'm not sure I do either

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head is exploding. Currently watching https://www.youtube.com/watch?v=O1Gu5b7rxbw

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is clunky. But for what you have this will have to work.
I just put this issue in and will get it out ASAP so we can do non-clunky things.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilsoft sorry for spam. Do you have a video / writeup on cancelling Asyncs manually? Not quite grokking it from the docs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In crocks you cannot cancel an Async from the inside, breaks way too many laws.
BUT you can return a function that will be called when a fork is cancelled. When you call fork it will give you back a function. When that function is called it will cancel the forked flow. Will not resolve/reject and will not run an more Asyncs in a flow that are not already in flight or settled.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was definitely thinking of this way too mutably. This makes sense. Thank you

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing it the way we decided to in crocks keeps all side effects at the edge (as you call fork at the edge it makes sense for cancelling (like when some side effect pushes a cancel button, etc). So @mgreystone HAS to do it this way for his flow because he does not want to cancel but Reject after an amount of time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilsoft, should we be cancelling the inner sent Async, in addition to reject-ing the outer Async?

Copy link
Contributor

@flintinatux flintinatux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the approach. I've written similar algorithms with Promises in the past. The one big question I've got is whether this is a good fit for sox, since it's not transport specific. We could do much of the same thing with a util function that accepts any Async, not just a sox one, and wraps it in another Async that handles the timeout. Seems like more of an managing-Asyncs thing than a sox thing.

client/index.js Outdated
@@ -64,6 +82,9 @@ const sox = (args = {}) => {
// send : String -> a -> Async Action
socket.send = send

// send : Object -> String -> a -> Async Action
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past we've used { k: v } in signatures, rather than Object. Following ramda a bit on that, I think.

client/index.js Outdated
sent = sent.bimap(cleanup, cleanup)
}

sent.fork(reject, resolve)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilsoft, should we be cancelling the inner sent Async, in addition to reject-ing the outer Async?

client/index.js Outdated
@@ -1,4 +1,5 @@
const action = require('@articulate/ducks/lib/action')
const error = require('@articulate/ducks/lib/error')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this list alphabetical.

@mgreystone
Copy link
Member Author

@flintinatux , @evilsoft has a crocks PR that will move a lot of this cruft to the crocks lib. See evilsoft/crocks#282. I think that will address most of your separation of concerns.... concerns...

Even so, i would argue that this is a sox feature. Because i don't just want to manage timeouts. I want to reject with the given action on timeout. That seems like a sox thing to me.

@flintinatux
Copy link
Contributor

@mgreystone, I'm ok with this approach then. Thanks for clarifying.

@mgreystone
Copy link
Member Author

@evilsoft @flintinatux @rpearce Crocks has been bumped (thank you!) & now using the new async race & rejectAfter functions. Ready for final review.

Copy link

@rpearce rpearce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

@pklingem
Copy link
Member

@mgreystone, I'm ok with this approach then. Thanks for clarifying.

them's mergin' words

@flintinatux
Copy link
Contributor

How incredibly simple this code has become.

@rpearce
Copy link

rpearce commented Aug 20, 2018

I dig it. Really nice @mgreystone

@mgreystone mgreystone merged commit f04496d into master Aug 21, 2018
@mgreystone mgreystone deleted the timeout branch August 21, 2018 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants