profile
viewpoint
Ibragimov Ruslan IRus @Heapy Minsk https://ibragimov.by/ Engineer, Developer, Speaker

sanity/pairAdjacentViolators 42

A JVM implementation of the Pair Adjacent Violators algorithm for isotonic regression

Heapy/kotlin-dev-proxy 17

Simple server for proxy requests and host static files written in Kotlin and Undertow.

IRus/social-architecture-ru 8

Полный перевод книги про построение сообществ: «Социальная архитектура»

IRus/git-selfie 5

Create pictures of yourself on every commit/push/whatever git hook. Linux, Git.

BelarusKUG/Course 3

Вводный курс в Kotlin

BelarusKUG/Kotlin-Everywhere 3

Materials from Kotlin/Everywhere Minsk event

Heapy/di-comparison 3

DI containers comparison

IRus/currency-pwa 3

PWA currency converter

IRus/3d-printing 2

3D models for printing

IRus/blog 2

Sources of ruslan.ibragimov.by

push eventJetBrains/kotlin-web-site

katia-energizer

commit sha 7786baa233af7b07dadfd58ec5a65181c293df1b

update: updated Kotlin Roadmap (#2014) * Updated the roadmap as of January 2021. * Added a changelog * Moved roadmap notes to the bottom, after the roadmap table. * Added a link to the YT board. * Added a TOC.

view details

push time in 2 hours

delete branch JetBrains/kotlin-web-site

delete branch : roadmap-update

delete time in 2 hours

PR merged JetBrains/kotlin-web-site

update: updated Kotlin Roadmap
  • Updated the roadmap as of January 2021.
  • Added a changelog
  • Moved roadmap notes to the bottom, after the roadmap table.
  • Added a link to the YT board.
  • Added a TOC.
+165 -159

1 comment

2 changed files

katia-energizer

pr closed time in 2 hours

push eventJetBrains/kotlin-web-site

Ekaterina.Volodko

commit sha 736f5a7cbd017b946f6c1682658a5e55e17e5484

chore: text edits

view details

push time in 3 hours

fork akuleshov7/diKTat

Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs

https://www.cqfn.org/diKTat/

fork in 3 hours

push eventJetBrains/kotlin-web-site

Ekaterina.Volodko

commit sha f7a81a7c3436181d60575a5a611161df44323f7f

chore: text edits

view details

push time in 3 hours

startedJakeWharton/dockerfile-shebang

started time in 3 hours

issue commentKotlin/KEEP

Random API

I would like to pitch for some random sampling methods such as

fun <E> List<E>.sampleRandom(random: Random = DefaultRandom): E
fun <E> List<E>.sampleRandomList(size: Int, random: Random = DefaultRandom): List<E>
fun <E> List<E>.sampleRandomSet(size: Int, random: Random = DefaultRandom): Set<E>
fun <E> List<E>.sampleRandomSet(size: Int, weights: List<Int> = LazyList(this.size) {i -> 1}): Set<E>

The benefit of having such functions in the stdlib is preventing developers from implementing naive-but-incorrect implementations themselves. For example, for sampleRandomList it could be tempting to do something like the following, which is incorrect because the result has a different distribution than initial Random.nextInt()

fun <E> List<E>.sampleRandomList(sampleSize: Int): List<E> {
    val selectedIndices = mutableSetOf<Int>()

    repeat(sampleSize) {
        do {
            val i: Int = Random.nextInt(indices)
            val wasNew = selectedIndices.add(i)
        } while(!wasNew)
    }

    return this.slice(selectedIndices)
}

Another inefficient approach could be the implementation below, which is very easy to implement with the current proposal, and thus even more probable to be a source of problems.

fun <E> List<E>.sampleRandomList(sampleSize: Int): List<E> = shuffled().take(sampleSize)

As far as I understand, one of the correct and efficient algorithms for sampling is "Vose's Alias" algorithm, of which I am frankly totally ignorant, but you can read about it here http://www.keithschwarz.com/darts-dice-coins/

Can you please explain, why the two methods you present for taking random samples are "naive-but-incorrect"? "Vose's Alias" which you cited is an algorithm for getting random numbers with a biased (non-uniform) distribution. I cannot see how this fits into your example.

ilya-g

comment created time in 4 hours

issue commentKotlin/kotlinx.coroutines

Flow.collect doesn't receive any values

Is there any chance to reproduce with some self-contained code?

yandroidUA

comment created time in 4 hours

delete branch Kotlin/kotlinx.coroutines

delete branch : yield-doc

delete time in 4 hours

push eventKotlin/kotlinx.coroutines

Vsevolod Tolstopyatov

commit sha 7548b83f0694ea30331fee296b2dfcd0c143c36b

Clarify yield documentation (#2466) Fixes #2464

view details

push time in 4 hours

PR merged Kotlin/kotlinx.coroutines

Reviewers
Clarify yield documentation

Fixes #2464

+2 -1

1 comment

1 changed file

qwwdfsad

pr closed time in 4 hours

pull request commentKotlin/kotlinx.coroutines

Clarify yield documentation

👍 Nice clarification. Thanks.

qwwdfsad

comment created time in 4 hours

issue commentKotlin/kotlinx.coroutines

Thread switching and interoperability using rxSingle wrapper

Interesting. I actually haven't considered that as I initially dismissed that dispatcher thinking that Unconfined refers to unconfined thread pool, i.e. a dispatcher that creates threads as needed instead of using a thread pool. Now that you pointed this out, I read the docs and I can see it's something completely different. This might be exactly the solution I was looking for.

vkislicins

comment created time in 11 hours

issue commentKotlin/kotlinx.coroutines

Thread switching and interoperability using rxSingle wrapper

Have you considered explicitly using rxSingle(Dispatchers.Unconfined) in order to let rxSingle continue using the thread provided by the Rx Scheduler?

vkislicins

comment created time in 11 hours

issue openedKotlin/kotlinx.coroutines

Thread switching and interoperability using rxSingle wrapper

I'm trying to interop Kotlin Flow with RxJava callers using kotlin-coroutines-rx2. All my consumers of the API are currently RxJava chains, which I'm planning to slowly migrate to coroutines. However, my data is exposed as Flow<T> that needs to be consumed by these Rx chains. The data is coming from Jetpack DataStore. I'm using coroutines-rx2 rxSingle to wrap the flow into a Single in order to satisfy the caller dependencies. I end up with a function like this:

override fun getData(): Single<Data> = rxSingle { dataStore.data.first() }

Which gets called from chains like this:

 repository.getData()
        .flatMap { someNetworkCall(it) }
        .subscribeOn(schedulerProvider.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe({ processResult(it) }, { processError(it) })

The threading of this looks like:

  1. getData() is called on a background thread from Schedulers IO
  2. rxSingle doesn't have a coroutine context and therefore the dispatcher defaults to DefaultDispatcher
  3. someNetworkCall now runs on the DefaultDispatcher instead of the IO, which would be expected by just reading the Rx chain

In my app, all the threading is at the top layer, where the subscribe is called. This thread switching that rxSingle does is not obvious to whoever's working with the API, and the thread injected and used in bottom layer where getData exists, might not satisfy the remaining of the Rx chain.

I'm not sure why rxSingle switches the thread context instead of using the one currently specified by the Rx scheduler, there's probably a good reason for it, but as I see it, my options for this are:

  1. Each time I'm using rxSingle to wrap a Flow, I can finish with switching the thread using .observeOn(). This doesn't really satisfy the requirement of being transparent to the caller of the function, as I will just default to an arbitrary thread i decide on, which most likely going to be observeOn(schedulers.io()) to be safe. So the same getData will look like override fun getData(): Single<Data> = rxSingle(backgroundDispatcher) { dataStore.data.first() }.observeOn(schedulers.io())

  2. Or I pass down a dispatcher to use from the Rx chain caller like repository.getData(schedulers.io().asCoroutineDispatcher()) and pass it to my rxSingle wrapping function: override fun getData(dispatcher: Dispatcher): Single<Data> = rxSingle(dispatcher) { dataStore.data.first() }

Both options are not great so I'm looking for some advice, maybe I'm missing something here?

created time in 12 hours

PR opened KotlinBy/awesome-kotlin

Add adamint/spotify-web-api-kotlin - multiplatform spotify api

Checklist:

  • [X] Is this pull request against the branch main?
+5 -0

0 comment

1 changed file

pr created time in 13 hours

push eventJetBrains/kotlin-web-site

Ekaterina.Volodko

commit sha 205983343ca2433b4389e47eb37725525cbc6cb7

chore: text edits

view details

push time in 16 hours

MemberEvent
PublicEvent

startedhyperion-project/hyperion.ng

started time in 19 hours

startedKotlin-Polytech/KotlinAsFirst2020

started time in 19 hours

startedKonloch/bytecode-viewer

started time in 20 hours

push eventKotlin/kotlinx.coroutines

Anders Ha

commit sha ba87db30686e5c55be9ea200c758cb14db51b889

[native-mt] Fix the errornous isDispatchNeeded check in Dispatchers.Main.immediate on Darwin platforms. (#2476) Fixes #2283

view details

push time in 20 hours

PR merged Kotlin/kotlinx.coroutines

[native-mt] Fix the errornous isDispatchNeeded check in Dispatchers.Main.immediate on Darwin platforms.

Resolves https://github.com/Kotlin/kotlinx.coroutines/issues/2283

First commit includes a test case that fails in both macosx64 background & main tests.

+11 -1

0 comment

2 changed files

andersio

pr closed time in 20 hours

delete branch Kotlin/kotlinx.coroutines

delete branch : pr/2476

delete time in 20 hours

delete branch Kotlin/kotlinx.coroutines

delete branch : pr/2477

delete time in 20 hours

push eventKotlin/kotlinx.coroutines

Anders Ha

commit sha cb19b9a88fb1a7b5f37e4c88cc3c6ecf13fc49ff

[native-mt] Fix ObjC autorelease object leaks with native-mt dispatchers (#2477) Fixes #2322

view details

push time in 20 hours

PR merged Kotlin/kotlinx.coroutines

Reviewers
[native-mt] Fix ObjC autorelease object leaks with native-mt dispatchers

Resolves #2322

While 1.4.30-M1 fixed Worker.execute() leaking ObjC autoreleasing objects when running native code on a K/N Worker thread (KT-42822), it does not address the issue at KoltinX Coroutines framework level.

More specifically, when tasks on an EventLoop call into native code, any autoreleasing object — especially many ObjC method return values — is effectively leaked <sup>[1]</sup>. This is because the first available autoreleasepool in the call stack is in workerMain(), and it wraps around a most likely never-returning <sup>[2]</sup> runEventLoop().

This PR introduced a failing test case of this bug, and fixed it by wrapping all Runnable.run() calls in EventLoopImplBase with an autoreleasepool (or nothing for non-Darwin targets). This is equivalent to the DISPATCH_AUTORELEASE_FREQUENCY_WORK_ITEM<sup>[3]</sup> in GCD.

An alternative to the per-item wrapping is integrating pool push/pop into runEventLoop(), with heruistics based on the park time returned by processNextEvent(). Not familiar enough about the particulars to try this out though.

<sup>[1]</sup> ... unless an autoreleasepool is declared in user code explicitly, which is a rare practice except for memory optimization. <sup>[2]</sup> Dispatchers.Default, for example. <sup>[3]</sup> ... which is not the default behaviour. GCD threads inherit autorelease pool management from NSRunLoop, which recreates pools for each runloop iteration.

+77 -2

1 comment

6 changed files

andersio

pr closed time in 20 hours

create barnchKotlin/kotlinx.coroutines

branch : pr/2477

created branch time in 21 hours

more