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

Add j.u.c.Flow #4792

Merged
merged 1 commit into from Jan 20, 2023
Merged

Add j.u.c.Flow #4792

merged 1 commit into from Jan 20, 2023

Conversation

armanbilge
Copy link
Member

https://docs.oracle.com/javase/9/docs/api/java/util/concurrent/Flow.html

Since they are just interfaces, what are we looking for in terms of tests?

@sjrd
Copy link
Member

sjrd commented Jan 19, 2023

The tests we do for pure interfaces are: create instances of it, "upcast" them to the interface type, call methods. This is to make sure that the binary API of the methods declared in the interfaces are actually.correct.

See for example https://github.com/scala-js/scala-js/blob/v1.12.0/test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/function/LongSupplierTest.scala

trait Processor[T, R] extends Subscriber[T] with Publisher[R]

trait Publisher[T] {
def subscribe(subscriber: Subscriber[T]): Unit
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def subscribe(subscriber: Subscriber[T]): Unit
def subscribe(subscriber: Subscriber[_ >: T]): Unit

Comment on lines 24 to 27
def onComplete(): Unit
def onError(throwable: Throwable): Unit
def onNext(item: T): Unit
def onSubscribe(subscription: Subscription): Unit
Copy link
Member

Choose a reason for hiding this comment

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

Please order the methods according the "Method Detail" section of the JavaDoc (not by alphabetical order).

Comment on lines 31 to 36
def cancel(): Unit
def request(n: Long): Unit
}
Copy link
Member

Choose a reason for hiding this comment

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

Same here (so swap them in this case).

@armanbilge armanbilge force-pushed the feature/juc-flow branch 2 times, most recently from ee4f2c2 to f177c4e Compare January 19, 2023 20:24
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Looks good except for some missing braces in the tests, to adhere to our coding style.


object FlowTest {

def makeProcessor[T, R](): Flow.Processor[T, R] =
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def makeProcessor[T, R](): Flow.Processor[T, R] =
def makeProcessor[T, R](): Flow.Processor[T, R] = {

Same for all the makeX methods.

According to our coding style:
https://github.com/scala-js/scala-js/blob/main/CODINGSTYLE.md#braces

@armanbilge
Copy link
Member Author

@sjrd sjrd merged commit fb20d6f into scala-js:main Jan 20, 2023
@armanbilge
Copy link
Member Author

armanbilge commented Feb 29, 2024

Update: thanks to this interface it is now trivial for users to consume FS2 streams in Laminar/Airstream, without either library knowing about each other. I think that's really cool :)

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

2 participants