package com.applovin.impl; import com.applovin.impl.fi; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /* loaded from: classes.dex */ public final class fi { private final Object a; private final String b; private final List c; private volatile boolean d; private volatile boolean e; private volatile Object f; private volatile Object g; public interface a { void a(Object obj); } public interface b { void a(boolean z, Object obj, Object obj2); } public boolean c() { return this.d; } public boolean d() { return this.d && !this.e; } public fi() { this(null); } public fi(String str) { this.a = new Object(); this.c = new ArrayList(); this.d = false; this.e = false; this.b = str; } public void a(b bVar) { synchronized (this.a) { try { if (!this.d) { this.c.add(bVar); } else { b(bVar); } } catch (Throwable th) { throw th; } } } public static fi c(Object obj) { return new fi().b(obj); } public String b() { String str = this.b; return str != null ? str : super.toString(); } public String toString() { String str; if (!this.d) { str = "Waiting"; } else if (this.e) { str = "Success -> " + this.f; } else { str = "Failed -> " + this.g; } return "Promise(" + b() + ": " + str + ")"; } public void a(final a aVar) { a(new b() { // from class: com.applovin.impl.fi$$ExternalSyntheticLambda0 @Override // com.applovin.impl.fi.b public final void a(boolean z, Object obj, Object obj2) { fi.a(fi.a.this, z, obj, obj2); } }); } public fi b(Object obj) { a(true, obj, null); return this; } public void a(final Runnable runnable) { a(new b() { // from class: com.applovin.impl.fi$$ExternalSyntheticLambda1 @Override // com.applovin.impl.fi.b public final void a(boolean z, Object obj, Object obj2) { fi.a(runnable, z, obj, obj2); } }); } private void b(b bVar) { try { bVar.a(this.e, this.f, this.g); } catch (Throwable th) { q6.a(th, "Promise callbacks must not throw exceptions", new Object[0]); } } public Object a() { q6.a(d()); return this.g; } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ void a(a aVar, boolean z, Object obj, Object obj2) { if (z) { return; } aVar.a(obj2); } /* JADX INFO: Access modifiers changed from: private */ public static /* synthetic */ void a(Runnable runnable, boolean z, Object obj, Object obj2) { if (z) { runnable.run(); } } public fi a(Object obj) { a(false, null, obj); return this; } private void a(boolean z, Object obj, Object obj2) { synchronized (this.a) { try { if (this.d) { return; } this.f = obj; this.g = obj2; this.e = z; this.d = true; Iterator it = this.c.iterator(); while (it.hasNext()) { b((b) it.next()); } this.c.clear(); } catch (Throwable th) { throw th; } } } }