<commit_before>package org.proofcafe.async;

import android.content.Context;
import android.util.Log;
import static org.proofcafe.async.Util.*;

public abstract class Async<A> {
	
	private volatile boolean interrupted = false;

	protected Async() {
	}

	protected abstract void execInternal(Context context, Object token, Cont<A> cont, Runnable ifFail);
	
	public void interrupt() {
		this.interrupted = true;
		Log.e("async", "interrupted");
	}
	
	protected void resetInterrupt() {
		this.interrupted = false;
	}

	protected final void runInternal(final Context context, final Object token, Cont<A> cont, final Runnable ifFail) {
		if(interrupted) {
			resetInterrupt();
			Util.runInUiThread(new Runnable(){
				public void run() {
					ifFail.run();
				}});
		} else {
			execInternal(context, token, cont, ifFail);
		}
	}

	public final void exec(final Context context, final Cont<A> cont, final Runnable ifFail, final boolean withDialog) {
		resetInterrupt();
		
		final AsyncListener listener = listener(context);
		final Object token = new Object();
		
		Util.runInUiThread(new Runnable() {<commit_msg>[async] add isInterrupted()<commit_after>package org.proofcafe.async;

import android.content.Context;
import android.util.Log;
import static org.proofcafe.async.Util.*;

public abstract class Async<A> {
	
	private volatile boolean interrupted = false;

	protected Async() {
	}

	protected abstract void execInternal(Context context, Object token, Cont<A> cont, Runnable ifFail);
	
	public void interrupt() {
		this.interrupted = true;
		Log.e("async", "interrupted");
	}
	
	protected void resetInterrupt() {
		this.interrupted = false;
	}
	
	public final boolean isInterrupted() {
		return interrupted;
	}

	protected final void runInternal(final Context context, final Object token, Cont<A> cont, final Runnable ifFail) {
		if(interrupted) {
			resetInterrupt();
			Util.runInUiThread(new Runnable(){
				public void run() {
					ifFail.run();
				}});
		} else {
			execInternal(context, token, cont, ifFail);
		}
	}

	public final void exec(final Context context, final Cont<A> cont, final Runnable ifFail, final boolean withDialog) {
		resetInterrupt();
		
		final AsyncListener listener = listener(context);
		final Object token = new Object();
		
		Util.runInUiThread(new Runnable() {
{'fraction_non_alphanumeric': 0.1099521946979574, 'fraction_numerical': 0.0, 'mean_word_length': 4.391100702576113, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '659493', 'n_tokens_mistral': 765, 'n_tokens_neox': 668, 'n_words': 202}