Jgafner
07/16/2021, 6:36 AMPitel
07/16/2021, 9:30 AMAyfri
07/16/2021, 11:44 AMjeggy
07/16/2021, 12:06 PMuser
07/16/2021, 1:03 PMOmkar Amberkar
07/16/2021, 3:15 PMsharedflow
which would be eventually replaced by network call polling every few seconds. This is what I am got so far but still not what I expect, my expectation
1. Start polling once at least one terminal operator is present collect
2. Stop polling when no terminal operator
3. Share same value across all the terminal operator collect
, but as you can see, the values are different.
Also to add, when I cancel
a pollingScope
, the send
function is still called since the flow is active and keeps throwing exception
due to job cancellation.
Help much appreciated!!!
@ExperimentalCoroutinesApi
fun poll(scope: CoroutineScope) = callbackFlow {
invokeOnClose { Timber.e("Debug: channel closed") }
while (true) {
try {
val nextInt = Random.nextInt(0, 100)
Timber.e("Debug: nextInt -> $nextInt")
send(nextInt)
delay(MIN_REFRESH_TIME_MS)
} catch (throwable: Throwable) {
Timber.e("Debug: error -> ${throwable.message}")
}
}
}.shareIn(scope = scope, replay = 1, started = SharingStarted.WhileSubscribed())
pollingScope.launch {
engine.poll(applicationScope).collect {
Timber.e("Debug: collect 1 -> $it")
}
}
pollingScope.launch {
engine.poll(applicationScope).collect {
Timber.e("Debug: collect 2 -> $it")
}
}
pollingScope.launch {
engine.poll(randomScope).collect {
Timber.e("Debug: collect 3 -> $it")
}
}
$poll: Debug: nextInt -> 59
$poll: Debug: nextInt -> 68
$poll: Debug: nextInt -> 73
$poll$3$invokeSuspend$$inlined$collect: Debug: collect 2 -> 73
$poll$2$invokeSuspend$$inlined$collect: Debug: collect 1 -> 59
$poll$4$invokeSuspend$$inlined$collect: Debug: collect 3 -> 68
andylamax
07/16/2021, 4:06 PMChetan Tuteja
07/17/2021, 11:48 AMLefko
07/18/2021, 9:32 AMJason Roberts
07/19/2021, 5:13 AMAmit Kumar Kar
07/19/2021, 8:17 AMuser
07/19/2021, 2:09 PMMohammad Jahidul Islam
07/19/2021, 2:58 PMNick
07/19/2021, 3:20 PMlateinit var
or assigning the value to a val
that way it’s not mutable?
Example lateinit var:
late init var foo: Bar()
fun goTime() {
foo = Bar()
println(foo)
}
Example var:
var foo: Bar? = null
fun goTime() {
val foo = foo ?: Bar()
println(foo)
}
Ifvwm
07/20/2021, 10:29 AMIfvwm
07/20/2021, 10:35 AMfun parseIntEither(s: String): Either<NumberFormatException, Int> =
if (s.matches(Regex("-?[0-9]+"))) Either.Right(s.toInt())
else Either.Left(NumberFormatException("$s is not a valid integer."))
val list = listOf("1", "2", "3").k().traverse(Either.applicative(), ::parseIntEither)
val failFastList = listOf("1", "abc", "3", "4s").k().traverse(Either.applicative(), ::parseIntEither)
red line under Either.applicative(),
Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6
I can't find a solution on IDEA, but it's ok on Android Studio, and IDEA using the same JDK 1.8 from Android Studio
Raed Ghazal
07/20/2021, 1:24 PMconst
list/array inside a companion object in kotlin?Ludovik
07/20/2021, 2:21 PMAyfri
07/20/2021, 4:52 PMallan.conda
07/20/2021, 10:15 PMJérémy CROS
07/21/2021, 12:30 PMclass Foo
class Bar(
private val foo: Foo
) {
override fun equals(other: Any?): Boolean {
if(other !is Bar) return false
return this.foo == other.foo // it works?
}
override fun hashCode(): Int {
return foo.hashCode()
}
}
fun test() {
val foo = Foo()
val bar = Bar(foo)
val test = bar.foo // private, cannot access
}
Could not find any documentation on this behavior.
I mean, seemed convenient but it just felt... weird that it worked on the equals override 🙂eygraber
07/22/2021, 5:16 AMT
where an inlined property that uses a with
scope on an instance of the same type as T
gets unwrapped to use the class instance instead of the actual one?
Something like (using custom extensions on JsonObject
):
@JvmInline
value class MyJson(val json: JsonObject) {
inline val type
get() = with(json.jsonObject("type") {
string("actual_type") // this crashes at runtime because it is looking for this field in the json property instead of the one from the with scope
}
}
Switching to `json.jsonObject("type").let { type ->`worksStephan Schroeder
07/22/2021, 7:15 AMnfrankel
07/22/2021, 2:27 PMPhillip Schichtel
07/22/2021, 8:32 PMio.github.gradle-nexus.publish-plugin
plugin and from(components["java"])
in the publication, then everything gets uploaded except the actual code jar: https://oss.sonatype.org/#nexus-search;quick~kognigy. This happens both with gradle 6.8 and 7.1. Am I missing something?jimn
07/22/2021, 9:11 PMfold
, or reduce
to this, finally, i just did it as a while loop. is there a one-liner for this ?
var acc = sim.outputRange.indices
val tree = sortedSetOf<Int>()
while (acc.isNotEmpty()) {
tree += acc;
acc = acc.map { this.usefulScope(it) }.flatten().filter {
it in sim.hiddenRange } - tree
}
Austin Paquette
07/22/2021, 9:38 PMclass Example(val id: Int) {
companion object {
fun <T, V> demo(property: KProperty1<T, V>, value: V): V? {
return null
}
}
}
// this works
val test1 = Example.demo(Example::id, 0)
// this works, but shouldn't pass validation
val test2 = Example.demo(Example::id, "1")
The idea is that I want to be able to infer the type of the passed-in property (in this case I would expect Int
. I feel like I'm close but not understanding something. Any help (or even suggestions of what to Google) would be awesome.user
07/23/2021, 7:58 AMDavid Smith
07/23/2021, 3:24 PMDavid Smith
07/23/2021, 4:12 PMDavid Smith
07/23/2021, 4:12 PMkevindmoore
07/23/2021, 4:26 PMandylamax
07/25/2021, 10:42 AM