Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
9d9e5d08
Unverified
Commit
9d9e5d08
authored
Jan 28, 2019
by
Allan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace cancellation checks with yield
parent
cf7ffd51
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
22 deletions
+7
-22
ChatRoomsViewModel.kt
.../rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
+4
-14
ConnectionManager.kt
...ocket/android/server/infraestructure/ConnectionManager.kt
+1
-3
IO.kt
app/src/main/java/chat/rocket/android/util/IO.kt
+2
-5
No files found.
app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
View file @
9d9e5d08
...
@@ -20,12 +20,8 @@ import chat.rocket.core.model.SpotlightResult
...
@@ -20,12 +20,8 @@ import chat.rocket.core.model.SpotlightResult
import
com.shopify.livedataktx.distinct
import
com.shopify.livedataktx.distinct
import
com.shopify.livedataktx.map
import
com.shopify.livedataktx.map
import
com.shopify.livedataktx.nonNull
import
com.shopify.livedataktx.nonNull
import
kotlinx.coroutines.experimental.*
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.delay
import
kotlinx.coroutines.experimental.isActive
import
kotlinx.coroutines.experimental.launch
import
kotlinx.coroutines.experimental.newSingleThreadContext
import
kotlinx.coroutines.experimental.withContext
import
timber.log.Timber
import
timber.log.Timber
import
java.lang.IllegalArgumentException
import
java.lang.IllegalArgumentException
import
kotlin.coroutines.experimental.coroutineContext
import
kotlin.coroutines.experimental.coroutineContext
...
@@ -53,18 +49,12 @@ class ChatRoomsViewModel(
...
@@ -53,18 +49,12 @@ class ChatRoomsViewModel(
// debounce, to not query while the user is writing
// debounce, to not query while the user is writing
delay
(
200
)
delay
(
200
)
// TODO - find a better way for cancellation checking
yield
()
if
(!
coroutineContext
.
isActive
)
return
@wrap
val
rooms
=
repository
.
search
(
string
).
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
val
rooms
=
repository
.
search
(
string
).
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
data
.
postValue
(
rooms
.
toMutableList
()
+
LoadingItemHolder
())
data
.
postValue
(
rooms
.
toMutableList
()
+
LoadingItemHolder
())
yield
()
if
(!
coroutineContext
.
isActive
)
return
@wrap
val
spotlight
=
spotlight
(
query
.
query
)
?.
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
val
spotlight
=
spotlight
(
query
.
query
)
?.
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
if
(!
coroutineContext
.
isActive
)
return
@wrap
yield
()
spotlight
?.
let
{
spotlight
?.
let
{
data
.
postValue
(
rooms
.
toMutableList
()
+
spotlight
)
data
.
postValue
(
rooms
.
toMutableList
()
+
spotlight
)
}.
ifNull
{
}.
ifNull
{
...
...
app/src/main/java/chat/rocket/android/server/infraestructure/ConnectionManager.kt
View file @
9d9e5d08
...
@@ -295,7 +295,7 @@ class ConnectionManager(
...
@@ -295,7 +295,7 @@ class ConnectionManager(
val
batch
=
ArrayList
<
T
>(
maxSize
)
val
batch
=
ArrayList
<
T
>(
maxSize
)
var
deadline
=
0L
// deadline for sending this batch to callback block
var
deadline
=
0L
// deadline for sending this batch to callback block
while
(
tru
e
)
{
while
(
isActiv
e
)
{
// when deadline is reached or size is exceeded, pass the batch to the callback block
// when deadline is reached or size is exceeded, pass the batch to the callback block
val
remainingTime
=
deadline
-
System
.
currentTimeMillis
()
val
remainingTime
=
deadline
-
System
.
currentTimeMillis
()
if
(
batch
.
isNotEmpty
()
&&
remainingTime
<=
0
||
batch
.
size
>=
maxSize
)
{
if
(
batch
.
isNotEmpty
()
&&
remainingTime
<=
0
||
batch
.
size
>=
maxSize
)
{
...
@@ -317,8 +317,6 @@ class ConnectionManager(
...
@@ -317,8 +317,6 @@ class ConnectionManager(
// when timeout is reached just finish select, note: no timeout when batch is empty
// when timeout is reached just finish select, note: no timeout when batch is empty
if
(
batch
.
isNotEmpty
())
onTimeout
(
remainingTime
.
orZero
())
{}
if
(
batch
.
isNotEmpty
())
onTimeout
(
remainingTime
.
orZero
())
{}
}
}
if
(!
isActive
)
break
}
}
}
}
}
}
...
...
app/src/main/java/chat/rocket/android/util/IO.kt
View file @
9d9e5d08
...
@@ -5,6 +5,7 @@ import chat.rocket.common.RocketChatNetworkErrorException
...
@@ -5,6 +5,7 @@ import chat.rocket.common.RocketChatNetworkErrorException
import
kotlinx.coroutines.experimental.TimeoutCancellationException
import
kotlinx.coroutines.experimental.TimeoutCancellationException
import
kotlinx.coroutines.experimental.delay
import
kotlinx.coroutines.experimental.delay
import
kotlinx.coroutines.experimental.isActive
import
kotlinx.coroutines.experimental.isActive
import
kotlinx.coroutines.experimental.yield
import
timber.log.Timber
import
timber.log.Timber
import
kotlin.coroutines.experimental.coroutineContext
import
kotlin.coroutines.experimental.coroutineContext
...
@@ -48,19 +49,15 @@ suspend fun <T> retryDB(
...
@@ -48,19 +49,15 @@ suspend fun <T> retryDB(
{
{
var
currentDelay
=
initialDelay
var
currentDelay
=
initialDelay
repeat
(
times
-
1
)
{
currentTry
->
repeat
(
times
-
1
)
{
currentTry
->
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
try
{
try
{
return
block
()
return
block
()
}
catch
(
e
:
SQLiteDatabaseLockedException
)
{
}
catch
(
e
:
SQLiteDatabaseLockedException
)
{
Timber
.
d
(
e
,
"failed call($currentTry): $description"
)
Timber
.
d
(
e
,
"failed call($currentTry): $description"
)
e
.
printStackTrace
()
e
.
printStackTrace
()
}
}
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
delay
(
currentDelay
)
delay
(
currentDelay
)
currentDelay
=
(
currentDelay
*
factor
).
toLong
().
coerceAtMost
(
maxDelay
)
currentDelay
=
(
currentDelay
*
factor
).
toLong
().
coerceAtMost
(
maxDelay
)
}
}
yield
()
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
return
block
()
// last attempt
return
block
()
// last attempt
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment