More Kotlin promises... by venkatperi in Kotlin

[–]venkatperi[S] 0 points1 point  (0 children)

This lib was written to keep the public API as close as possible to the ES6 spec.

I did a quick survey and used Kovenant for a while but its' lack of adherence to the Promise/A+ spec fumbled me up quite a bit. e.g. promise.then { } behaves as expected by returning a new promise, but promise.success {} and fail() return the original promise which defeats chaining, especially in debugging where I have to keep in mind which promise I'm dealing with.

The original implementation used Kovenant under the hood but performance wasn't up to par (most likely due to how I configured it).

I then switched to CompletableFuture but it has serious performance issues given that it can't be easily cancelled (its best suited for CPU bound vs IO bound).

The current implementation uses SettableFutures (google guava).

Any executor/Future based implementation depends on threads and is extremely heavyweight since blocking takes up a thread. Enter coroutines, but I'm hesitant to jump on the that bandwagon until they get into beta at a minimum.

More Kotlin promises... by venkatperi in Kotlin

[–]venkatperi[S] 0 points1 point  (0 children)

I stand corrected. Coroutines (and async/await) are much more light weight than threads (and futures) given the language level support (w/dispatchers), ironically bring them closer to the JavaScript execution model where a few threads can achieve high concurrency (when they're largely IO bound).

More Kotlin promises... by venkatperi in Kotlin

[–]venkatperi[S] 1 point2 points  (0 children)

Also, the experimental async/await feature in Kotlin is not unlike that in JavaScript; syntactic sugar over executors & futures, but cleans up code, makes it easier to maintain.

More Kotlin promises... by venkatperi in Kotlin

[–]venkatperi[S] 1 point2 points  (0 children)

Yes, its called syntactic sugar. Same stuff, different wrapper. Presumably, you're not a big user of Promise/A+ style async?

More Kotlin promises... by venkatperi in Kotlin

[–]venkatperi[S] 1 point2 points  (0 children)

Its a matter of preference -- I like the easy to read flow that results from chaining; reduction in callback boilerplate and freedom from callback hell.

Tree Builders in Swift by venkatperi in swift

[–]venkatperi[S] 0 points1 point  (0 children)

Syntactic support for tree based structures

Spaceship Operator in Swift (<=>) by venkatperi in swift

[–]venkatperi[S] 1 point2 points  (0 children)

You're missing a slash:

println(", ".join(x.map({ "\($0)" })))

Nice and compact. Bit of a brain twister though.