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
5fab419e
Unverified
Commit
5fab419e
authored
Jan 28, 2019
by
Allan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Catch cancellation exceptions for chat room live data
parent
9d9e5d08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
21 deletions
+19
-21
ChatRoomsViewModel.kt
.../rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
+17
-16
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 @
5fab419e
...
@@ -24,8 +24,6 @@ import kotlinx.coroutines.experimental.*
...
@@ -24,8 +24,6 @@ import kotlinx.coroutines.experimental.*
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.android.UI
import
timber.log.Timber
import
timber.log.Timber
import
java.lang.IllegalArgumentException
import
java.lang.IllegalArgumentException
import
kotlin.coroutines.experimental.coroutineContext
class
ChatRoomsViewModel
(
class
ChatRoomsViewModel
(
private
val
connectionManager
:
ConnectionManager
,
private
val
connectionManager
:
ConnectionManager
,
...
@@ -45,20 +43,23 @@ class ChatRoomsViewModel(
...
@@ -45,20 +43,23 @@ class ChatRoomsViewModel(
return
@switchMap
if
(
query
.
isSearch
())
{
return
@switchMap
if
(
query
.
isSearch
())
{
this
@ChatRoomsViewModel
.
query
.
wrap
(
runContext
)
{
_
,
data
:
MutableLiveData
<
RoomsModel
>
->
this
@ChatRoomsViewModel
.
query
.
wrap
(
runContext
)
{
_
,
data
:
MutableLiveData
<
RoomsModel
>
->
val
string
=
(
query
as
Query
.
Search
).
query
try
{
val
string
=
(
query
as
Query
.
Search
).
query
// debounce, to not query while the user is writing
delay
(
200
)
// debounce, to not query while the user is writing
yield
()
delay
(
200
)
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
()
yield
()
val
spotlight
=
spotlight
(
query
.
query
)
?.
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
val
spotlight
=
spotlight
(
query
.
query
)
?.
let
{
mapper
.
map
(
it
,
showLastMessage
=
this
.
showLastMessage
)
}
yield
()
yield
()
spotlight
?.
let
{
spotlight
?.
let
{
data
.
postValue
(
rooms
.
toMutableList
()
+
spotlight
)
data
.
postValue
(
rooms
.
toMutableList
()
+
spotlight
)
}.
ifNull
{
}.
ifNull
{
data
.
postValue
(
rooms
)
data
.
postValue
(
rooms
)
}
}
catch
(
ignore
:
CancellationException
)
{
}
}
}
}
}
else
{
}
else
{
...
...
app/src/main/java/chat/rocket/android/util/IO.kt
View file @
5fab419e
...
@@ -22,20 +22,17 @@ suspend fun <T> retryIO(
...
@@ -22,20 +22,17 @@ suspend fun <T> retryIO(
{
{
var
currentDelay
=
initialDelay
var
currentDelay
=
initialDelay
repeat
(
times
-
1
)
{
currentTry
->
repeat
(
times
-
1
)
{
currentTry
->
if
(!
coroutineContext
.
isActive
)
throw
TimeoutCancellationException
(
"job canceled"
)
yield
(
)
try
{
try
{
return
block
()
return
block
()
}
catch
(
e
:
RocketChatNetworkErrorException
)
{
}
catch
(
e
:
RocketChatNetworkErrorException
)
{
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
}
}
...
...
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