Hi all,
I’ve just applied the async
/await
implementation from Using coroutines to avoid callback hell when using XMLHttpRequest to my toy project, in #12 Refactored to use continuations, but ... · HughG/partial-order@2e4e2d4 · GitHub.
It looks much nicer than before, but the calls to Promise<T>.await
don’t seem to actually wait; that is, they don’t prevent the rest of an async
block from executing immediately.
This is all using
- IntelliJ 2017.1.2
- Kotlin 1.1.2_2 (compiler and plugin)
- pouchdb 5.3.1
- CouchDB 1.6.1
- jquery 3.2.1 with Kotlin API from ts2tk
- Firefox Developer Edition 54.0a2 64-bit
- Windows 10
With the refactoring in that commit, the (browser console) output of my example is like this:
Object { } kotlin-test-app.js:129:13
Loading graph ... kotlin-test-app.js:311:13
Nodes by rank ... kotlin-test-app.js:222:5
TypeError: graph.ranks is undefined: listByRank@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:223:9
this["kotlin-test-app"]</Coroutine$main$lambda.prototype.doResume@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:189:13
CoroutineImpl.prototype.doResumeWrapper_0@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/lib/kotlin.js:3805:20
CoroutineImpl.prototype.resume_11rb$@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/lib/kotlin.js:3794:5
startCoroutine_0@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/lib/kotlin.js:28974:5
async$lambda/<@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:1528:7
async@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:1532:12
main@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:218:17
this["kotlin-test-app"]<@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:1695:3
@file:///C:/Users/hughg/Documents/dev/partial-order/web/js/app/kotlin-test-app.js:4:27
kotlin-test-app.js:1553:5
Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead[Learn More] kotlin-test-app.js:1699
Object { } kotlin-test-app.js:129:13
GET
XHR
http://localhost:5984/ranking/ [HTTP/1.1 404 Object Not Found 0ms]
The above 404 is totally normal. PouchDB is just detecting if the remote exists.
However, at the previous commit, it looks more like this:
Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead[Learn More] kotlin-test-app.js:1202
GET
XHR
http://localhost:5984/ranking/ [HTTP/1.1 404 Object Not Found 2ms]
The above 404 is totally normal. PouchDB is just detecting if the remote exists. pouchdb-5.3.1.js:5800:5
Object { db_name: "ranking", doc_count: 0, doc_del_count: 0, update_seq: 0, purge_seq: 0, compact_running: false, disk_size: 79, data_size: 0, instance_start_time: "1494695881360340", disk_format_version: 6, 4 more… } kotlin-test-app.js:43:7
Bulk store inputs: kotlin-test-app.js:920:7
Object { _id: "N_github:partial-order/HughG/14", type: "N", description: "Gradle task for ts2kt" } kotlin-test-app.js:924:9
Object { _id: "N_github:partial-order/HughG/13", type: "N", description: "Integrate NodeJS packages into Grad…" } kotlin-test-app.js:924:9
...
Bulk store results: kotlin-test-app.js:936:7
Object { ok: true, id: "N_github:partial-order/HughG/14", rev: "1-dcfc41c1ca0f9be813c95c3982cc27c8" } kotlin-test-app.js:940:9
Object { ok: true, id: "N_github:partial-order/HughG/13", rev: "1-e85cb281e1f5cc08ee612099926c0a37" } kotlin-test-app.js:940:9
...
Loading graph ... kotlin-test-app.js:178:5
Nodes: kotlin-test-app.js:123:7
Object { total_rows: 13, offset: 0, rows: Array[13] } kotlin-test-app.js:124:7
Node N_github:partial-order/HughG/10: Investigate Yested for UI kotlin-test-app.js:136:11
Node N_github:partial-order/HughG/11: Support pagination when fetching from GitHub kotlin-test-app.js:136:11
...
Edges: kotlin-test-app.js:155:7
Object { total_rows: 13, offset: 0, rows: Array[0] } kotlin-test-app.js:156:7
Loading graph ... done. kotlin-test-app.js:172:7
Nodes by rank ... kotlin-test-app.js:80:5
Caching ranks ... kotlin-test-app.js:525:7
0 0 'Investigate Yested for UI' <- 'null' kotlin-test-app.js:515:7
1 0 'Support pagination when fetching from GitHub' <- 'null' kotlin-test-app.js:515:7
...
In the Kotlin source, after the refactor, listByRank
is failing because it’s trying to access graph.ranks
when the graph
hasn’t been initialised. In fact, the db
hasn’t even been initialised: it outputs Object { }
near the start where previously it output Object { db_name: "ranking", doc_count: 0, doc_del_count: 0, update_seq: 0, purge_seq: 0, compact_running: false, disk_size: 79, data_size: 0, instance_start_time: "1494695881360340", disk_format_version: 6, 4 more… } kotlin-test-app.js:43:7
.
Any clues, from anyone willing to check out and dig through my source code? If there are no takers for that, I can try to boil it down to a small repeatable case. I did try to dig into the generated JavaScript but in the presence of coroutines it’s pretty impenetrable.