Skip to content

Conversation

@hoc081098
Copy link
Owner

Status

READY/IN DEVELOPMENT/HOLD

Breaking Changes

YES | NO

Description

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Requirements

  • Dump api
  • Update README
  • Update CHANGELOG
  • Add tests
  • Add docs

@codecov
Copy link

codecov bot commented Oct 29, 2023

Codecov Report

Attention: Patch coverage is 0% with 222 lines in your changes are missing coverage. Please review.

Project coverage is 68.43%. Comparing base (aa451b5) to head (70f7633).
Report is 3 commits behind head on master.

❗ Current head 70f7633 differs from pull request most recent head 55d6e50. Consider uploading reports for the commit 55d6e50 to get more accurate results

Files Patch % Lines
...otlin/com/hoc081098/flowext/publishWithSelector.kt 0.00% 196 Missing and 4 partials ⚠️
...otlin/com/hoc081098/flowext/internal/SimpleLazy.kt 0.00% 11 Missing ⚠️
...om/hoc081098/flowext/internal/SimpleSuspendLazy.kt 0.00% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #189       +/-   ##
===========================================
- Coverage   87.91%   68.43%   -19.49%     
===========================================
  Files          37       37               
  Lines         811     1020      +209     
  Branches      110      154       +44     
===========================================
- Hits          713      698       -15     
- Misses         53      273      +220     
- Partials       45       49        +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hoc081098 hoc081098 requested a review from Copilot August 30, 2025 14:19
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a "publish with selector" functionality that allows for advanced flow transformation using a selector-based pattern. The implementation enables multiple flows to be derived from a single source flow with shared subscription and selective processing.

  • Implements publish function with selector scope for creating multiple derived flows from a single source
  • Adds comprehensive state management for selector scopes with thread-safe operations
  • Provides specialized DSL annotations and interfaces for type-safe selector operations

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
publishWithSelector.kt Main implementation with publish function, selector scopes, state management, and example usage
SimpleSuspendLazy.kt Thread-safe lazy initialization for suspend functions with cleanup capabilities
SimpleLazy.kt Thread-safe lazy initialization for regular functions with cleanup capabilities
AtomicRef.kt Atomic reference utilities with loop and update operations
FlowExt.api API definitions for the new publish selector functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

val stateRef = AtomicRef<SelectorScopeState<T>>(SelectorScopeState.Init)

override fun <R> select(block: SelectorFunction<T, R>): Flow<R> {
println("call select with block: $block")
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Debug print statement should be removed from production code. Consider using a proper logging framework or removing this debug output.

Suggested change
println("call select with block: $block")

Copilot uses AI. Check for mistakes.
Comment on lines +261 to +265
println(
"onCompleteSelectedFlow: completedCount = ${(updated as? SelectorScopeState.Frozen)?.completedCount}, " +
"size = ${state.blocks.size}, " +
"(index = $index)",
)
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Debug print statements should be removed from production code. Consider using a proper logging framework or removing these debug outputs.

Copilot uses AI. Check for mistakes.
clear()
}

println("onCompleteSelectedFlow: cancel the publish scope")
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Debug print statement should be removed from production code. Consider using a proper logging framework or removing this debug output.

Suggested change
println("onCompleteSelectedFlow: cancel the publish scope")

Copilot uses AI. Check for mistakes.
}

suspend fun send(value: T) {
println("send: $value")
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Debug print statement should be removed from production code. Consider using a proper logging framework or removing this debug output.

Suggested change
println("send: $value")

Copilot uses AI. Check for mistakes.
}

fun close(e: Throwable?) {
println("close: $e")
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Debug print statement should be removed from production code. Consider using a proper logging framework or removing this debug output.

Suggested change
println("close: $e")

Copilot uses AI. Check for mistakes.
Comment on lines +402 to +405
println("cancel: $e")
transitionToClosed { it.cancel(e) }
}
}
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

Debug print statement should be removed from production code. Consider using a proper logging framework or removing this debug output.

Suggested change
println("cancel: $e")
transitionToClosed { it.cancel(e) }
}
}
transitionToClosed { it.cancel(e) }
}
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +439 to +493
@OptIn(FlowExtPreview::class, ExperimentalCoroutinesApi::class)
public suspend fun main() {
flow<Any?> {
println("Collect...")
delay(100)
emit(1)
delay(100)
emit(2)
delay(100)
emit(3)
delay(100)
emit("4")
}.onEach { println(">>> onEach: $it") }
.publish {
delay(100)

merge(
select { flow ->
delay(1)
val sharedFlow = flow.shareIn()

interval(0, 100)
.onEach { println(">>> interval: $it") }
.flatMapMerge { value ->
timer(value, 50)
.withLatestFrom(sharedFlow)
.map { it to "shared" }
}.takeUntil(sharedFlow.filter { it == 3 })
},
select { flow ->
flow
.filterIsInstance<Int>()
.filter { it % 2 == 0 }
.map { it to "even" }
.take(1)
},
select { flow ->
flow
.filterIsInstance<Int>()
.filter { it % 2 != 0 }
.map { it to "odd" }
.take(1)
},
select { flow ->
flow
.filterIsInstance<String>()
.map { it to "string" }
.take(1)
},
)
}
.toList()
.also { println(it) }
.let { check(it == listOf(Pair(1, "odd"), Pair(2, "even"), Pair("4", "string"))) }
}
Copy link

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

The main function appears to be a test or example and should not be included in production library code. Consider moving this to a test file or removing it entirely.

Suggested change
@OptIn(FlowExtPreview::class, ExperimentalCoroutinesApi::class)
public suspend fun main() {
flow<Any?> {
println("Collect...")
delay(100)
emit(1)
delay(100)
emit(2)
delay(100)
emit(3)
delay(100)
emit("4")
}.onEach { println(">>> onEach: $it") }
.publish {
delay(100)
merge(
select { flow ->
delay(1)
val sharedFlow = flow.shareIn()
interval(0, 100)
.onEach { println(">>> interval: $it") }
.flatMapMerge { value ->
timer(value, 50)
.withLatestFrom(sharedFlow)
.map { it to "shared" }
}.takeUntil(sharedFlow.filter { it == 3 })
},
select { flow ->
flow
.filterIsInstance<Int>()
.filter { it % 2 == 0 }
.map { it to "even" }
.take(1)
},
select { flow ->
flow
.filterIsInstance<Int>()
.filter { it % 2 != 0 }
.map { it to "odd" }
.take(1)
},
select { flow ->
flow
.filterIsInstance<String>()
.map { it to "string" }
.take(1)
},
)
}
.toList()
.also { println(it) }
.let { check(it == listOf(Pair(1, "odd"), Pair(2, "even"), Pair("4", "string"))) }
}

Copilot uses AI. Check for mistakes.
@hoc081098
Copy link
Owner Author

@copilot review PR

@hoc081098
Copy link
Owner Author

@codex review PR AND GIVE FEEDBACKS

@chatgpt-codex-connector
Copy link

Review Summary

Testing

No tests were run.

View task →

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