Skip to content
This repository was archived by the owner on Aug 10, 2024. It is now read-only.

Commit 30253d1

Browse files
committed
* Asynchronicity was breaking outbound message order, remove it.
* ktor was including logback-classic, which is bad practice for a library, will file a bug
1 parent 723415d commit 30253d1

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

build.gradle

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.github.sanity'
2-
version '0.0.36'
2+
version '0.0.37'
33

44
buildscript {
55
ext.kotlin_version = '1.1.1'
@@ -70,9 +70,15 @@ dependencies {
7070
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.12'
7171
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:0.12'
7272

73-
compile 'org.jetbrains.ktor:ktor-core:0.3.0'
74-
compile 'org.jetbrains.ktor:ktor-netty:0.3.0'
75-
compile 'org.jetbrains.ktor:ktor-websockets:0.3.0'
73+
compile ('org.jetbrains.ktor:ktor-core:0.3.0') {
74+
exclude group : 'ch.qos.logback', module : 'logback-classic'
75+
}
76+
compile ('org.jetbrains.ktor:ktor-netty:0.3.0') {
77+
exclude group : 'ch.qos.logback', module : 'logback-classic'
78+
}
79+
compile('org.jetbrains.ktor:ktor-websockets:0.3.0') {
80+
exclude group : 'ch.qos.logback', module : 'logback-classic'
81+
}
7682

7783
compile 'io.github.microutils:kotlin-logging:1.4.2'
7884

src/main/kotlin/com/github/sanity/kweb/Kweb.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,13 @@ class Kweb(val port: Int,
110110
thread.stackTrace.pruneAndDumpStackTo(logStatementBuilder)
111111
val logStatement = logStatementBuilder.toString()
112112
logger.warn { logStatement }
113-
}) {buildPage(RootReceiver(newClientId, httpRequestInfo,this@Kweb))
113+
}) {
114+
buildPage(RootReceiver(newClientId, httpRequestInfo,this@Kweb))
115+
logger.debug { "Outbound message queue size after buildPage is ${outboundBuffer.queueSize()}"}
114116
}
115117
} else {
116118
buildPage(RootReceiver(newClientId, httpRequestInfo, this@Kweb))
119+
logger.debug { "Outbound message queue size after buildPage is ${outboundBuffer.queueSize()}"}
117120
}
118121
for (plugin in plugins) {
119122
execute(newClientId, plugin.executeAfterPageCreation())

src/main/kotlin/com/github/sanity/kweb/RootReceiver.kt

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package com.github.sanity.kweb
22

33
import com.github.sanity.kweb.dom.Document
44
import com.github.sanity.kweb.plugins.KWebPlugin
5-
import kotlinx.coroutines.experimental.CommonPool
6-
import kotlinx.coroutines.experimental.async
75
import org.jetbrains.ktor.util.ValuesMap
86
import java.util.concurrent.CompletableFuture
97
import kotlin.reflect.KClass
@@ -29,11 +27,11 @@ class RootReceiver(private val clientId: String, val httpRequestInfo: HttpReques
2927
}
3028
}
3129

32-
fun execute(js: String) = async(CommonPool){
30+
fun execute(js: String) {
3331
cc.execute(clientId, js)
3432
}
3533

36-
fun executeWithCallback(js: String, callbackId: Int, callback: (String) -> Unit) = async(CommonPool){
34+
fun executeWithCallback(js: String, callbackId: Int, callback: (String) -> Unit) {
3735
cc.executeWithCallback(clientId, js, callbackId, callback)
3836
}
3937

@@ -47,7 +45,7 @@ class RootReceiver(private val clientId: String, val httpRequestInfo: HttpReques
4745
}
4846

4947

50-
fun evaluateWithCallback(js: String, rh: RootReceiver.() -> Boolean) = async(CommonPool){
48+
fun evaluateWithCallback(js: String, rh: RootReceiver.() -> Boolean) {
5149
cc.evaluate(clientId, js, { rh.invoke(RootReceiver(clientId, httpRequestInfo, cc, it)) })
5250
}
5351

src/main/kotlin/com/github/sanity/kweb/browserConnection/OutboundChannel.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.sanity.kweb.browserConnection
22

3-
import io.netty.channel.Channel
4-
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame
53
import org.jetbrains.ktor.websocket.Frame
64
import org.jetbrains.ktor.websocket.WebSocket
75
import java.util.concurrent.ConcurrentLinkedQueue
@@ -28,5 +26,7 @@ sealed class OutboundChannel {
2826
queue = null
2927
return r
3028
}
29+
30+
fun queueSize() = queue?.size
3131
}
3232
}

src/main/kotlin/com/github/sanity/kweb/demos/async/async.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package com.github.sanity.kweb.demos.async
22

33
import com.github.sanity.kweb.Kweb
44
import com.github.sanity.kweb.dom.element.creation.createElement
5-
import com.github.sanity.kweb.dom.element.modification.setAttribute
65
import com.github.sanity.kweb.dom.element.modification.addText
6+
import com.github.sanity.kweb.dom.element.modification.setAttribute
77
import com.github.sanity.kweb.dom.element.read.read
88
import kotlinx.coroutines.experimental.future.await
99
import kotlinx.coroutines.experimental.future.future
10+
import mu.KotlinLogging
1011

1112
/**
1213
* Created by ian on 1/11/17.
1314
*/
15+
16+
private val logger = KotlinLogging.logger {}
1417
fun main(args: Array<String>) {
1518
println("Visit http://127.0.0.1:8091/ in your browser...")
1619
Kweb(8091) {

0 commit comments

Comments
 (0)