Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
01e1819f
Commit
01e1819f
authored
Jun 12, 2020
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ambiguous coroutineContext
parent
6e9f445d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
7 deletions
+5
-7
core/build.gradle.kts
core/build.gradle.kts
+1
-1
core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt
...om/github/shadowsocks/subscription/SubscriptionService.kt
+4
-6
No files found.
core/build.gradle.kts
View file @
01e1819f
...
...
@@ -66,7 +66,7 @@ tasks.register<Exec>("cargoClean") {
tasks
.
clean
.
dependsOn
(
"cargoClean"
)
dependencies
{
val
coroutinesVersion
=
"1.3.
6
"
val
coroutinesVersion
=
"1.3.
7
"
val
roomVersion
=
"2.2.5"
val
workVersion
=
"2.4.0-beta01"
...
...
core/src/main/java/com/github/shadowsocks/subscription/SubscriptionService.kt
View file @
01e1819f
...
...
@@ -95,9 +95,7 @@ class SubscriptionService : Service(), CoroutineScope {
}
Core
.
notification
.
notify
(
NOTIFICATION_ID
,
notification
.
build
())
counter
=
0
val
workers
=
urls
.
asIterable
().
map
{
url
->
async
(
Dispatchers
.
IO
)
{
fetchJson
(
url
,
urls
.
size
(),
notification
)
}
}
val
workers
=
urls
.
asIterable
().
map
{
url
->
fetchJsonAsync
(
url
,
urls
.
size
(),
notification
)
}
try
{
val
localJsons
=
workers
.
awaitAll
()
withContext
(
Dispatchers
.
Main
)
{
...
...
@@ -127,20 +125,20 @@ class SubscriptionService : Service(), CoroutineScope {
return
START_NOT_STICKY
}
private
suspend
fun
fetchJson
(
url
:
URL
,
max
:
Int
,
notification
:
NotificationCompat
.
Builder
):
File
?
{
private
fun
fetchJsonAsync
(
url
:
URL
,
max
:
Int
,
notification
:
NotificationCompat
.
Builder
)
=
async
(
Dispatchers
.
IO
)
{
val
tempFile
=
File
.
createTempFile
(
"subscription-"
,
".json"
,
cacheDir
)
try
{
(
url
.
openConnection
()
as
HttpURLConnection
).
useCancellable
{
tempFile
.
outputStream
().
use
{
out
->
inputStream
.
copyTo
(
out
)
}
}
return
tempFile
tempFile
}
catch
(
e
:
IOException
)
{
Timber
.
d
(
e
)
launch
(
Dispatchers
.
Main
)
{
Toast
.
makeText
(
this
@SubscriptionService
,
e
.
readableMessage
,
Toast
.
LENGTH_LONG
).
show
()
}
if
(!
tempFile
.
delete
())
tempFile
.
deleteOnExit
()
return
null
null
}
finally
{
withContext
(
Dispatchers
.
Main
)
{
counter
+=
1
...
...
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