@@ -8,10 +8,13 @@ import com.margelo.nitro.nitrofs.NitroFile
88import com.margelo.nitro.nitrofs.NitroFileEncoding
99import com.margelo.nitro.nitrofs.NitroFileStat
1010import com.margelo.nitro.nitrofs.NitroUploadOptions
11+ import kotlinx.coroutines.CoroutineScope
12+ import kotlinx.coroutines.Dispatchers
1113
1214class HybridNitroFS : HybridNitroFSSpec () {
1315 val context = NitroModules .applicationContext ? : error(" React Native context not found" )
1416 val nitroFsImpl = NitroFSImpl (context)
17+ val ioScope = CoroutineScope (Dispatchers .IO )
1518
1619 override val BUNDLE_DIR : String
1720 get() = " "
@@ -34,7 +37,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
3437 data : String ,
3538 encoding : NitroFileEncoding
3639 ): Promise <Unit > {
37- return Promise .async {
40+ return Promise .async(ioScope) {
3841 try {
3942 nitroFsImpl.writeFile(path, data, encoding)
4043 } catch (e: Exception ) {
@@ -48,7 +51,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
4851 path : String ,
4952 encoding : NitroFileEncoding
5053 ): Promise <String > {
51- return Promise .async {
54+ return Promise .async(ioScope) {
5255 try {
5356 nitroFsImpl.readFile(path, encoding)
5457 } catch (e: Exception ) {
@@ -62,7 +65,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
6265 srcPath : String ,
6366 destPath : String
6467 ): Promise <Unit > {
65- return Promise .async {
68+ return Promise .async(ioScope) {
6669 try {
6770 nitroFsImpl.copyFile(srcPath, destPath)
6871 } catch (e: Exception ) {
@@ -80,7 +83,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
8083 }
8184
8285 override fun unlink (path : String ): Promise <Boolean > {
83- return Promise .async {
86+ return Promise .async(ioScope) {
8487 try {
8588 nitroFsImpl.unlink(path)
8689 } catch (e: Exception ) {
@@ -91,7 +94,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
9194 }
9295
9396 override fun mkdir (path : String ): Promise <Boolean > {
94- return Promise .async {
97+ return Promise .async(ioScope) {
9598 try {
9699 nitroFsImpl.mkdir(path)
97100 } catch (e: Exception ) {
@@ -102,7 +105,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
102105 }
103106
104107 override fun stat (path : String ): Promise <NitroFileStat > {
105- return Promise .async {
108+ return Promise .async(ioScope) {
106109 nitroFsImpl.stat(path)
107110 }
108111 }
@@ -112,7 +115,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
112115 uploadOptions : NitroUploadOptions ,
113116 onProgress : ((Double , Double ) -> Unit )?
114117 ): Promise <Unit > {
115- return Promise .async {
118+ return Promise .async(ioScope) {
116119 try {
117120 nitroFsImpl.uploadFile(file, uploadOptions, onProgress)
118121 } catch (e: Exception ) {
@@ -128,7 +131,7 @@ class HybridNitroFS: HybridNitroFSSpec() {
128131 destinationPath : String ,
129132 onProgress : ((Double , Double ) -> Unit )?
130133 ): Promise <NitroFile > {
131- return Promise .async {
134+ return Promise .async(ioScope) {
132135 try {
133136 nitroFsImpl.downloadFile(serverUrl, fileName, destinationPath, onProgress)
134137 NitroFile (
0 commit comments