Skip to content

Commit

Permalink
Step 9.2, execution order attained.
Browse files Browse the repository at this point in the history
  • Loading branch information
legalimpurity committed Jul 14, 2018
1 parent 2d1c92f commit 46f5638
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.legalimpurity.asynctaskwrittenfromscratch.MyAsyncTaskCode

import com.legalimpurity.asynctaskwrittenfromscratch.MyAsyncTaskCode.executors.ExecutorProvider
import java.util.concurrent.Callable
import java.util.concurrent.Future

abstract class MyAsyncTask(){

Expand All @@ -10,14 +12,17 @@ abstract class MyAsyncTask(){
abstract fun onPostExecute()

fun execute() {
ExecutorProvider.mainThreadTaskExecutor?.execute {
onPreExecute()
}
ExecutorProvider.backgroundTaskExecutor?.execute {
doInBackground()
}
ExecutorProvider.mainThreadTaskExecutor?.execute {
onPostExecute()
onPreExecute()

ExecutorProvider.backgroundTaskExecutor?.let {
val future : Future<Boolean> = it.submit(Callable<Boolean>
{
doInBackground()
true
})
future.get()
}

onPostExecute()
}
}

0 comments on commit 46f5638

Please sign in to comment.