-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
246 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
android/src/main/java/com/reactnativecompressor/Utils/HttpCallManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.reactnativecompressor.Utils | ||
|
||
import okhttp3.Call | ||
|
||
class HttpCallManager { | ||
private var resumableCalls: MutableMap<String, Call?> = HashMap() | ||
|
||
fun registerTask(call: Call, uuid: String) { | ||
resumableCalls[uuid] = call | ||
} | ||
|
||
fun taskForId(uuid: String): Call? { | ||
return resumableCalls[uuid] | ||
} | ||
|
||
// will use in future | ||
fun downloadTaskForId(uuid: String): Call? { | ||
return taskForId(uuid) | ||
} | ||
|
||
fun uploadTaskForId(uuid: String): Call? { | ||
return taskForId(uuid) | ||
} | ||
|
||
fun taskPop(): Call? { | ||
val lastUuid = resumableCalls.keys.lastOrNull() | ||
val lastCall = resumableCalls.remove(lastUuid) | ||
return lastCall | ||
} | ||
|
||
fun unregisterTask(uuid: String) { | ||
resumableCalls.remove(uuid) | ||
} | ||
|
||
fun cancelAllTasks() { | ||
for ((_, call) in resumableCalls) { | ||
call?.cancel() | ||
} | ||
resumableCalls.clear() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.