1
1
package com.squareup.tracing
2
2
3
- import kotlinx.coroutines.CancellationException
4
3
import kotlinx.coroutines.CoroutineDispatcher
5
4
import kotlinx.coroutines.CoroutineScope
6
5
import kotlinx.coroutines.Dispatchers.IO
7
6
import kotlinx.coroutines.ObsoleteCoroutinesApi
8
7
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
9
- import kotlinx.coroutines.channels.ClosedSendChannelException
10
8
import kotlinx.coroutines.channels.SendChannel
11
9
import kotlinx.coroutines.channels.actor
12
10
import kotlinx.coroutines.channels.consumeEach
@@ -74,7 +72,7 @@ public class TraceEncoder(
74
72
val timestamp = getTimestampNow()
75
73
val processNameEvent = createProcessNameEvent(processName, processId, timestamp)
76
74
val threadNameEvent = createThreadNameEvent(threadName, processId, threadId, timestamp)
77
- events.safeOffer (listOf (processNameEvent, threadNameEvent))
75
+ events.trySend (listOf (processNameEvent, threadNameEvent))
78
76
79
77
return object : TraceLogger {
80
78
override fun log (eventBatch : List <TraceEvent >) = log(processId, threadId, eventBatch)
@@ -99,7 +97,7 @@ public class TraceEncoder(
99
97
val chromeTraceEvents = eventBatch.map {
100
98
it.toChromeTraceEvent(threadId, processId, timestampMicros)
101
99
}
102
- events.safeOffer (chromeTraceEvents)
100
+ events.trySend (chromeTraceEvents)
103
101
}
104
102
105
103
internal fun log (
@@ -109,23 +107,10 @@ public class TraceEncoder(
109
107
) {
110
108
val timestampMicros = getTimestampNow()
111
109
val chromeTraceEvents = event.toChromeTraceEvent(threadId, processId, timestampMicros)
112
- events.safeOffer (listOf (chromeTraceEvents))
110
+ events.trySend (listOf (chromeTraceEvents))
113
111
}
114
112
115
113
private fun getTimestampNow (): Long = start.elapsedNow
116
-
117
- /* *
118
- * Like [SendChannel.offer] but won't throw if the channel is closed.
119
- */
120
- private fun <T > SendChannel<T>.safeOffer (value : T ) {
121
- try {
122
- trySend(value)
123
- } catch (e: CancellationException ) {
124
- // Ignore it.
125
- } catch (e: ClosedSendChannelException ) {
126
- // Ignore it.
127
- }
128
- }
129
114
}
130
115
131
116
/* *
0 commit comments