Skip to content

feat: add QueueClosed singleton instance for Java API#1377

Merged
He-Pin merged 1 commit intoapache:mainfrom
Roiocam:queue-offer-result-api
Jun 27, 2024
Merged

feat: add QueueClosed singleton instance for Java API#1377
He-Pin merged 1 commit intoapache:mainfrom
Roiocam:queue-offer-result-api

Conversation

@Roiocam
Copy link
Member

@Roiocam Roiocam commented Jun 25, 2024

Motivation

new API for Java users, used to detect queue completion.

QueueOfferResult offerResult = queue.offer(params);

if (offerResult == QueueOfferResult.enqueued()) {
    // logic...
} else if (offerResult == QueueOfferResult.dropped()) {
    // logic...
} else if (offerResult instanceof QueueOfferResult.Failure) {
    // logic...
} else if (offerResult == QueueOfferResult.closed()) {
    // logic...
} else {
    // logic...
}

截屏2024-06-25 10 08 44

"return a QueueClosed result if completed" in {
val sub = TestSubscriber.probe[Int]()
val queue =
Source.queue[Int](10).toMat(Sink.fromSubscriber(sub))(Keep.left).run()
queue.complete()
queue.isCompleted shouldBe true
queue.offer(1) should be(QueueOfferResult.QueueClosed)
sub.expectSubscriptionAndComplete()

@Roiocam Roiocam requested a review from He-Pin June 25, 2024 02:01
@He-Pin
Copy link
Member

He-Pin commented Jun 25, 2024

You can use isEqueued too.

@He-Pin He-Pin added the t:stream Pekko Streams label Jun 25, 2024
@He-Pin He-Pin added this to the 1.1.0-M2 milestone Jun 25, 2024
@He-Pin He-Pin merged commit 3f4d52e into apache:main Jun 27, 2024
@pjfanning pjfanning added the release notes Need to release note label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes Need to release note t:stream Pekko Streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants