mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Handle remote operations, both sync and non-sync
This commit is contained in:
		
							parent
							
								
									9aff678fa4
								
							
						
					
					
						commit
						d73ee43e3d
					
				| @ -192,7 +192,7 @@ public abstract class RemoteOperation<T> implements Runnable { | ||||
| 
 | ||||
|     /** | ||||
|      * Synchronously executes the remote operation | ||||
|      * <p> | ||||
|      * | ||||
|      * Do not call this method from the main thread. | ||||
|      * | ||||
|      * @param client Client object to reach an ownCloud server during the execution of | ||||
|  | ||||
| @ -20,14 +20,22 @@ | ||||
| package com.owncloud.android.lib.common.operations | ||||
| 
 | ||||
| suspend fun <T> awaitToRemoteOperationResult(remoteOperation: suspend () -> RemoteOperationResult<T>): T { | ||||
|     remoteOperation.invoke().also { | ||||
|         return handleRemoteOperationResult(it) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|     val remoteOperationResult = remoteOperation.invoke() | ||||
| fun <T> waitForRemoteOperationResult(remoteOperation: () -> RemoteOperationResult<T>): T { | ||||
|     remoteOperation.invoke().also { | ||||
|         return handleRemoteOperationResult(it) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| private fun <T> handleRemoteOperationResult(remoteOperationResult: RemoteOperationResult<T>): T { | ||||
|     if (remoteOperationResult.isSuccess) { | ||||
|         return remoteOperationResult.data | ||||
|     } | ||||
| 
 | ||||
|     // Errors | ||||
|     when (remoteOperationResult.code) { | ||||
|         RemoteOperationResult.ResultCode.UNHANDLED_HTTP_CODE -> throw Exception() | ||||
|         RemoteOperationResult.ResultCode.UNAUTHORIZED -> throw Exception() | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user