<commit_before>package com.taig.android.concurrent

import android.os.{AsyncTask, Handler, Looper}

import scala.concurrent.duration.Duration
import scala.concurrent.{CanAwait, ExecutionContext, TimeoutException}
import scala.util.Try

case class Future[+T]( body: => T ) extends scala.concurrent.Future[T]
{
	private var result: Option[Try[T]] = None

	AsyncTask.THREAD_POOL_EXECUTOR.execute(
	{
		result = Some( Try( body ) )
		Future.handler.post( onComplete( null ) )
	}: Unit )

	override def onComplete[U]( f: ( Try[T] ) => U )( implicit executor: ExecutionContext ): Unit = ???

	override def isCompleted = result.isDefined

	override def value = result

	@scala.throws[Exception]( classOf[Exception] )
	override def result( atMost: Duration )( implicit permit: CanAwait ): T = ???

	@scala.throws[InterruptedException]( classOf[InterruptedException] )
	@scala.throws[TimeoutException]( classOf[TimeoutException] )
	override def ready( atMost: Duration )( implicit permit: CanAwait ): Future[T] = ???
}

object Future
{
	private val handler = new Handler( Looper.getMainLooper )
}<commit_msg>Added simple Future implementation that runs its callbacks on the main thread<commit_after>package com.taig.android.concurrent

import android.os.{AsyncTask, Handler, Looper}

import scala.concurrent.duration.Duration
import scala.concurrent.{CanAwait, ExecutionContext, TimeoutException}
import scala.util.Try
import com.taig.android._
import scala.collection.mutable

class Future[T]( body: => T ) extends scala.concurrent.Future[T]
{
	private var result: Option[Try[T]] = None

	private val tasks = new mutable.ListBuffer[( Try[T] ) => Any]

	AsyncTask.THREAD_POOL_EXECUTOR.execute(
	{
		result = Some( Try( body ) )

		Future.this.synchronized
		{
			Future.handler.post( tasks.foreach( _( result.get ) ) )
		}
	}: Unit )

	override def onComplete[U]( f: ( Try[T] ) => U )( implicit executor: ExecutionContext ) = synchronized
	{
		if( isCompleted )
		{
			f( result.get )
		}
		else
		{
			tasks.append( f )
		}
	}

	override def isCompleted = result.isDefined

	override def value = result

	@scala.throws[InterruptedException]( classOf[InterruptedException] )
	@scala.throws[TimeoutException]( classOf[TimeoutException] )
	override def ready( atMost: Duration )( implicit permit: CanAwait ) = null.asInstanceOf[this.type]

	@scala.throws[Exception]( classOf[Exception] )
	override def result( atMost: Duration )( implicit permit: CanAwait ) = null.asInstanceOf[T]
}

object Future
{
	private lazy val handler = new Handler( Looper.getMainLooper )

	def apply[T]( body: => T ) = new Future[T]( body )
}
{'fraction_non_alphanumeric': 0.12082853855005754, 'fraction_numerical': 0.0, 'mean_word_length': 4.873873873873874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3431785', 'n_tokens_mistral': 868, 'n_tokens_neox': 824, 'n_words': 207}