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

Buffer support for Node request body #33

Merged
merged 5 commits into from
May 18, 2017
Merged

Buffer support for Node request body #33

merged 5 commits into from
May 18, 2017

Conversation

owickstrom
Copy link
Collaborator

@rightfold: Thought I'd break the changes we discussed in #11 up into smaller PRs, so here's just the Buffer support. The String instance we had before now uses the same readBodyAsBuffer as the Buffer instance, which means the BUFFER effect spreads all over in existing code using readBody. 😞 I'm OK with that for now, though. We can provide some effect alias type for convenience.

I'm thankful for any feedback!

@rightfold
Copy link
Contributor

Looks good to me 👌🏻

To get rid of the effect you can use ByteString, which doesn't need effects for any of the operation, and has the same performance characteristics for concatenation.

@owickstrom
Copy link
Collaborator Author

Right, I forgot about ByteString. By the way, do you any plans on making it portable across PureScript backends? Then we could use it more in the core parts/APIs, if needed (basically like WAI depends on ByteString in Haskell).

@rightfold
Copy link
Contributor

rightfold commented May 17, 2017

No concrete plans but open to the idea. Shouldn't be difficult except the dependency on node-buffers.

chunks <- makeVar' []
res <- liftEff $
catchException (pure <<< Left) (Right <$> fillBody stream chunks completeBody)
either throwError (const (takeVar completeBody)) res
where
fillBody stream chunks completeBody = do
Copy link
Contributor

Choose a reason for hiding this comment

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

Stream.onError?

Copy link
Collaborator Author

@owickstrom owickstrom May 17, 2017

Choose a reason for hiding this comment

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

This part catches the EXCEPTION effect from Stream.onData (which seems to be thrown if the Node stream emits a Chunk that is not a String or a Buffer.) How that relates to Stream.onError, I'm not sure, but we should perhaps handle the onError case as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Stream API is so messy... 😞

Copy link
Contributor

@rightfold rightfold May 17, 2017

Choose a reason for hiding this comment

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

It would be nice to wrap purescript-node-streams with purescript-aff-coroutines. It should not be very difficult. The coroutine could emit (Either Error Buffer), and it could then be wrapped by another coroutine that uses ExceptT and emits Buffer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll check that out. Maybe do that as a separate PR?

Copy link
Contributor

@rightfold rightfold May 17, 2017

Choose a reason for hiding this comment

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

Sounds good, then we can easily abandon it if it doesn't work out.

@owickstrom
Copy link
Collaborator Author

owickstrom commented May 18, 2017

@rightfold added onError handling. Should we merge? Did not add coroutines yet, but we should absolutely consider it. Perhaps also take into account that it would add a couple of new transient dependencies as well.

@owickstrom owickstrom mentioned this pull request May 18, 2017
@rightfold
Copy link
Contributor

Sounds good 👍🏻

@owickstrom owickstrom merged commit 60bde7a into master May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants