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

Download streams #41

Merged
merged 8 commits into from
Aug 31, 2016
Merged

Download streams #41

merged 8 commits into from
Aug 31, 2016

Conversation

hmil
Copy link
Owner

@hmil hmil commented Aug 27, 2016

Implementation of the long awaited download streams. Addresses half of #7 .
WIP status:

  • working prototype
  • tests
  • validation
  • readme

hmil added 4 commits August 23, 2016 22:23
Conflicts:
	README.md
	js/src/main/scala/fr/hmil/roshttp/BrowserDriver.scala
	js/src/main/scala/fr/hmil/roshttp/HttpDriver.scala
	js/src/main/scala/fr/hmil/roshttp/NodeDriver.scala
	jvm/src/main/scala/fr/hmil/roshttp/HttpDriver.scala
	shared/src/main/scala/fr/hmil/roshttp/AbstractDriver.scala
	shared/src/main/scala/fr/hmil/roshttp/HttpRequest.scala
getStringFromBuffer(buffer, charset)
})
// TODO: We might not want to depend on monifu's Scheduler
.asFuture
Copy link
Owner Author

Choose a reason for hiding this comment

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

@sjrd Need your advice here. Monix needs an implicit Scheduler in order to use asFuture. The Scheduler is a subclass of ExecutionContext, which means that even though my interface allows the user to provide an ExecutionContext, I cannot use it because monix wants its own brand of ExecutionContext.

Copy link

Choose a reason for hiding this comment

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

Well, the enclosing apply method takes an Observable, so it depends on Monix anyway, right? In that case, I guess apply should require an implicit Scheduler rather than an ExecutionContext.

Copy link
Owner Author

Choose a reason for hiding this comment

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

But what if the user uses his own ExecutionContext throughout the project and then imports RösHTTP. From our discussion in #34 , it seems that this is likely the case. In this situation the user is forced to use a Scheduler instead...

Copy link

Choose a reason for hiding this comment

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

Well, you can't have your cake and eat it too.

If you're basing yourself on top of Monix, you have to play by Monix' rules. If it wants an implicit Scheduler, then yes, you need to demand a Scheduler from your users. Unless you can internally synthesize a valid Scheduler from an ExecutionContext, but I doubt that (otherwise Monix would take ECs to begin with).

If you don't want to impose the Scheduler tax on your users (which, I agree, is desirable), then you cannot use parts of the Monix API that require Schedulers.

Copy link

Choose a reason for hiding this comment

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

Where's the definition of asFuture? Maybe it can be generalized upstream to work with a normal EC.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It seems that there is no way to avoid the Scheduler. Plus the user has to provide a Scheduler anyway if he wants to use the streaming interface.
I should then probably replace all ExecutionContext parameters with Scheduler instead to make the whole API more consistent.

Copy link

Choose a reason for hiding this comment

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

I should then probably replace all ExecutionContext parameters with Scheduler instead to make the whole API more consistent.

I don't think so. I think it's good to require as little as possible from your users. That way, say they're only using the batch APIs, they can use any EC they already have. If they're using the streaming API as well, they can have an implicit Scheduler, and it will also be valid for methods requiring an implicit EC because Scheduler <: EC.

Copy link
Owner Author

Choose a reason for hiding this comment

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

The thing is that both the batch and streaming APIs are backed by the same stream-based backend call (which is what this piece of code is about). This avoids code duplication, reduces the risks of bugs and does probably have little effect on performance for basic usages. Therefore, a Scheduler is required even for the batch API.

Copy link

Choose a reason for hiding this comment

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

Ah, well ... I guess then it doesn't really matter all that much.

@hmil
Copy link
Owner Author

hmil commented Aug 29, 2016

Response streams will emulate a streaming behavior in the browser because XHR does not allow true streaming. But there is hope! => #46

Chrome cannot timeout on the response body because it buffers the whole response before emitting any event (hopefully #45 should level things a bit).

@hmil hmil merged commit e0789bd into v2.0.0 Aug 31, 2016
@hmil hmil deleted the streams branch August 31, 2016 05:57
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.

2 participants