Skip to content

Commit

Permalink
Use I/O dispatcher for global data I/O in DefaultArchiver
Browse files Browse the repository at this point in the history
  • Loading branch information
randomnetcat committed Jan 3, 2024
1 parent 92e19f5 commit d70c9ce
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/kotlin/org/randomcat/agorabot/util/DefaultArchiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,16 @@ private suspend fun receiveGlobalData(
metadataPath: Path,
globalDataDir: Path,
) {
coroutineScope {
launch {
usePathGenerator(metadataPath) { metadataGenerator ->
usePathGenerator(globalDataDir.resolve("users.json")) { usersGenerator ->
usePathGenerator(globalDataDir.resolve("roles.json")) { rolesGenerator ->
usePathGenerator(globalDataDir.resolve("channels.json")) { channelsGenerator ->
// Here, do all the opening and closing on the I/O dispatcher, so blocking reads/writes don't block on the default
// dispatcher, but then return to the default dispatcher for the actual work, which should not be doing much
// blocking I/O (and, in any case, receiveGlobalDataWithGenerators can switch dispatchers itself if it needs to).

withContext(Dispatchers.IO) {
usePathGenerator(metadataPath) { metadataGenerator ->
usePathGenerator(globalDataDir.resolve("users.json")) { usersGenerator ->
usePathGenerator(globalDataDir.resolve("roles.json")) { rolesGenerator ->
usePathGenerator(globalDataDir.resolve("channels.json")) { channelsGenerator ->
withContext(Dispatchers.Default) {
receiveGlobalDataWithGenerators(
dataChannel = dataChannel,
guild = guild,
Expand Down

0 comments on commit d70c9ce

Please sign in to comment.