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

build: update sbt and using sbt-tpolcat #57

Merged
merged 10 commits into from Dec 30, 2020

Conversation

ngbinh
Copy link
Sponsor Contributor

@ngbinh ngbinh commented Dec 29, 2020

  • Update sbt to 1.4.6
  • Update scala to 2.13.4
  • Start using
    sbt-tpolcat
  • Un-deprecated EventStream.fromSeq: @raquo this is something I am not sure about. I am not sure what is the appropriate replacement for EventStream.fromSeq. WDYT?

@ngbinh ngbinh requested a review from raquo December 29, 2020 06:52
.gitignore Outdated Show resolved Hide resolved
@raquo
Copy link
Owner

raquo commented Dec 29, 2020

@ngbinh Thanks for the PR!

I actually already un-deprecated EventStream.fromSeq locally, just didn't have a chance to push it yet. Coming soon.

@ngbinh
Copy link
Sponsor Contributor Author

ngbinh commented Dec 29, 2020

@raquo thanks for the reviews. I think address them all. Please take another look when you have time.

@@ -90,7 +91,7 @@ trait Observable[+A] {
def debugLog(prefix: String = "event", when: A => Boolean = _ => true): Self[A] = {
map(value => {
if (when(value)) {
println(prefix + ": ", value.asInstanceOf[js.Any])
println(prefix + ": " + value.asInstanceOf[js.Any])
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

👍 =)

@@ -126,7 +128,7 @@ object Observer {
if (onTryParam.isDefinedAt(nextValue)) {
onTryParam(nextValue)
} else {
nextValue.fold(err => AirstreamError.sendUnhandledError(err), identity)
nextValue.fold(err => AirstreamError.sendUnhandledError(err), _ => ())
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

I couldn't figure out why the success value case is dropped here. Maybe like this:

nextValue.failed.foreach { err => 
  AirstreamError.sendUnhandledError(err) 
}

?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

good catch!

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

hmm, Try,failed return a Failure in case of success. It would not as be clear as fold in this case IMHO.

Copy link
Sponsor Contributor

@yurique yurique Dec 29, 2020

Choose a reason for hiding this comment

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

Yeah, and because of that foreach will only kick in when the initial try is a failure. It's like with futures:

val f: Future[String] = ???
f.failed.foreach { case exception => ... }

With fold we're supposed to pass in a pure function, but we're dong side-effects and discarding the resulting Try.

Not insisting, but for me the intent was not clear initially :)

Copy link
Owner

Choose a reason for hiding this comment

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

failed certainly looks nicer, but has a cost I'm not willing to pay in library code. With failed, on every incoming (non-error) event we would be initializing and discarding an exception: Failure(new UnsupportedOperationException("Success.failed")). And it seems that this will also generate a stack trace for that exception, which isn't super cheap.

If the intent of this line is unclear, we could add a comment to clarify, but what should it say? The code itself already says that it's reporting unhandled errors.

Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

maybe like this then? :)

nextValue match {
  case Failure(err) => AirstreamError.sendUnhandledError(err)
  case _ => // nothing to do
}

Copy link
Owner

@raquo raquo Dec 30, 2020

Choose a reason for hiding this comment

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

Last time I checked, maybe a couple years ago, pattern matches in scala.js were said to be not efficient. Things probably improved since then, but I don't have time to check the generated code atm.

I guess I'm just not sure what's trippy about this particular fold. The codebase is full of fold-s, this one having an empty case doesn't seem all that special to me.

@yurique
Copy link
Sponsor Contributor

yurique commented Dec 29, 2020

fromSeq seems to be a useful part of the API. And with emitOnce it seems to be flexible enough.

But, I tried to see how and why exactly I use it — and couldn't find calls to it in my code anymore :) Only fromValue.

.travis.yml Outdated
@@ -9,8 +9,8 @@ jdk:
- oraclejdk11

scala:
- 2.12.10
- 2.13.1
- 2.12.11
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

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

latest seems to be 2.12.12

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

👍

@raquo raquo changed the base branch from master to next-0.12 December 30, 2020 01:40
@raquo raquo merged commit 181a487 into raquo:next-0.12 Dec 30, 2020
@raquo
Copy link
Owner

raquo commented Dec 30, 2020

Thanks @ngbinh I rebased and merged this into next-0.12, where the next release is shaping up.

@ngbinh ngbinh deleted the build/sbt-tpolcat branch December 30, 2020 01:49
@raquo
Copy link
Owner

raquo commented Jan 5, 2021

@ngbinh Do you know how to disable the "unused imports / variables" scalac option only in Test? It's useful, but I found it's really annoying for tests as I like to temporarily comment out stuff when fixing tests, and then the rule fails compilation.

@ngbinh
Copy link
Sponsor Contributor Author

ngbinh commented Jan 5, 2021

@raquo should be fairly easy. Do you want me to make a PR on top of #48 for that?

@raquo
Copy link
Owner

raquo commented Jan 5, 2021 via email

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

3 participants