Skip to content

Instantly share code, notes, and snippets.

@tophyr
Last active August 29, 2015 14:00
Show Gist options
  • Save tophyr/5b198ed6fc7abd295586 to your computer and use it in GitHub Desktop.
Save tophyr/5b198ed6fc7abd295586 to your computer and use it in GitHub Desktop.
Git merge troubles
public Result<T> getSync() {
T ret;
try {
try {
try {
ret = m_Loader.doLoad();
return Result.success(ret);
} catch (NoResultException e) {
if (m_Loader.getChainLoader() == null)
throw new UnsupportedOperationException("If there is no chained loader, doLoad() must return a result.");
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
}
} catch (ChainLoaderException e) {
return Result.failure(e);
}
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
}
public T getSync() {
try {
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
return t;
} else {
synchronized (m_Lock) {
m_Loader.registerListener(0, this);
m_Loader.startLoading();
try {
m_Lock.wait();
} catch (InterruptedException ignored) { }
m_Loader.unregisterListener(this);
return m_Data;
}
}
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
}
diff --git a/library/src/main/java/com/docusign/forklift/AsyncChainLoader.java b/library/src/main/java/com/docusign/forklift/AsyncChainLoader.java
index 61d9e01..bb725c9 100644
--- a/library/src/main/java/com/docusign/forklift/AsyncChainLoader.java
+++ b/library/src/main/java/com/docusign/forklift/AsyncChainLoader.java
@@ -25,27 +25,20 @@ public abstract class AsyncChainLoader<T> extends AsyncTaskLoader<Result<T>>
m_Loader = loader;
}
- @Override
- protected Result<T> getSync() {
+ public Result<T> getSync() {
T ret;
- m_Loader.reset(); // start fresh TODO: this violates the documented contract that onReset() is always called from main thread
try {
try {
try {
- m_Loader.m_State = LOADING_SELF;
ret = m_Loader.doLoad();
return Result.success(ret);
} catch (NoResultException e) {
if (m_Loader.getChainLoader() == null)
throw new UnsupportedOperationException("If there is no chained loader, doLoad() must return a result.");
- m_Loader.m_State = LOADING_CHAIN;
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
-
- if (m_Loader.m_State == INITIALIZED)
- throw new ChainLoaderException("Load was cancelled");
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
}
@@ -53,7 +46,7 @@ public abstract class AsyncChainLoader<T> extends AsyncTaskLoader<Result<T>>
return Result.failure(e);
}
} finally {
- m_Loader.reset(); // leave in a fresh state, too TODO: this violates the documented contract that onReset() is always called from main thread
+ m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
}
}
diff --git a/library/src/main/java/com/docusign/forklift/LoaderHelper.java b/library/src/main/java/com/docusign/forklift/LoaderHelper.java
index 578e083..421647a 100644
--- a/library/src/main/java/com/docusign/forklift/LoaderHelper.java
+++ b/library/src/main/java/com/docusign/forklift/LoaderHelper.java
@@ -32,8 +32,7 @@ public class LoaderHelper<T> implements Loader.OnLoadCompleteListener<T> {
}
}
- protected T getSync() {
- m_Loader.reset(); // start in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
+ public T getSync() {
try {
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
@Override
protected Result<T> getSync() {
T ret;
m_Loader.reset(); // start fresh TODO: this violates the documented contract that onReset() is always called from main thread
try {
try {
try {
<<<<<<< HEAD
try {
try {
||||||| merged common ancestors
=======
m_Loader.m_State = LOADING_SELF;
>>>>>>> stash@{0}
ret = m_Loader.doLoad();
return Result.success(ret);
} catch (NoResultException e) {
if (m_Loader.getChainLoader() == null)
throw new UnsupportedOperationException("If there is no chained loader, doLoad() must return a result.");
<<<<<<< HEAD
||||||| merged common ancestors
try {
=======
m_Loader.m_State = LOADING_CHAIN;
>>>>>>> stash@{0}
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
if (m_Loader.m_State == INITIALIZED)
throw new ChainLoaderException("Load was cancelled");
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
}
} catch (ChainLoaderException e) {
return Result.failure(e);
}
<<<<<<< HEAD
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
||||||| merged common ancestors
=======
} finally {
m_Loader.reset(); // leave in a fresh state, too TODO: this violates the documented contract that onReset() is always called from main thread
}
>>>>>>> stash@{0}
}
<<<<<<< HEAD
public T getSync() {
try {
||||||| merged common ancestors
public T getSync() {
=======
protected T getSync() {
m_Loader.reset(); // start in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
try {
>>>>>>> stash@{0}
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
return t;
} else {
synchronized (m_Lock) {
m_Loader.registerListener(0, this);
m_Loader.startLoading();
try {
m_Lock.wait();
} catch (InterruptedException ignored) { }
m_Loader.unregisterListener(this);
return m_Data;
}
}
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
}
@Override
protected Result<T> getSync() {
T ret;
m_Loader.reset(); // start fresh TODO: this violates the documented contract that onReset() is always called from main thread
try {
try {
<<<<<<< Updated upstream
try {
ret = m_Loader.doLoad();
return Result.success(ret);
} catch (NoResultException e) {
if (m_Loader.getChainLoader() == null)
throw new UnsupportedOperationException("If there is no chained loader, doLoad() must return a result.");
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
}
} catch (ChainLoaderException e) {
return Result.failure(e);
||||||| merged common ancestors
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
} catch (ChainLoaderException chainEx) {
return Result.failure(chainEx);
=======
try {
m_Loader.m_State = LOADING_SELF;
ret = m_Loader.doLoad();
return Result.success(ret);
} catch (NoResultException e) {
if (m_Loader.getChainLoader() == null)
throw new UnsupportedOperationException("If there is no chained loader, doLoad() must return a result.");
m_Loader.m_State = LOADING_CHAIN;
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
if (m_Loader.m_State == INITIALIZED)
throw new ChainLoaderException("Load was cancelled");
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
}
} catch (ChainLoaderException e) {
return Result.failure(e);
>>>>>>> Stashed changes
}
<<<<<<< Updated upstream
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
||||||| merged common ancestors
} catch (ChainLoaderException e) {
return Result.failure(e);
=======
} finally {
m_Loader.reset(); // leave in a fresh state, too TODO: this violates the documented contract that onReset() is always called from main thread
>>>>>>> Stashed changes
}
}
<<<<<<< Updated upstream
public T getSync() {
try {
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
return t;
} else {
synchronized (m_Lock) {
m_Loader.registerListener(0, this);
m_Loader.startLoading();
try {
m_Lock.wait();
} catch (InterruptedException ignored) { }
m_Loader.unregisterListener(this);
return m_Data;
}
}
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
||||||| merged common ancestors
public T getSync() {
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
m_Loader.reset();
return t;
} else {
synchronized (m_Lock) {
m_Loader.registerListener(0, this);
m_Loader.startLoading();
try {
m_Lock.wait();
} catch (InterruptedException ignored) { }
m_Loader.reset();
m_Loader.unregisterListener(this);
return m_Data;
}
}
=======
protected T getSync() {
m_Loader.reset(); // start in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
try {
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
return t;
} else {
synchronized (m_Lock) {
m_Loader.registerListener(0, this);
m_Loader.startLoading();
try {
m_Lock.wait();
} catch (InterruptedException ignored) { }
m_Loader.unregisterListener(this);
return m_Data;
}
}
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
>>>>>>> Stashed changes
}
@Override
protected Result<T> getSync() {
T ret;
m_Loader.reset(); // start fresh TODO: this violates the documented contract that onReset() is always called from main thread
try {
try {
try {
m_Loader.m_State = LOADING_SELF;
ret = m_Loader.doLoad();
return Result.success(ret);
} catch (NoResultException e) {
if (m_Loader.getChainLoader() == null)
throw new UnsupportedOperationException("If there is no chained loader, doLoad() must return a result.");
m_Loader.m_State = LOADING_CHAIN;
m_Loader.getChainLoader().unregisterListener(m_Loader);
ret = LoaderHelper.getSync(m_Loader.getChainLoader()).get();
m_Loader.getChainLoader().registerListener(0, m_Loader);
if (m_Loader.m_State == INITIALIZED)
throw new ChainLoaderException("Load was cancelled");
m_Loader.onFallbackDelivered(ret, null); // TODO: this doesn't understand PARTIAL!
return Result.success(ret);
}
} catch (ChainLoaderException e) {
return Result.failure(e);
}
} finally {
m_Loader.reset(); // leave in a fresh state, too TODO: this violates the documented contract that onReset() is always called from main thread
}
}
protected T getSync() {
m_Loader.reset(); // start in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
try {
if (m_Loader instanceof AsyncTaskLoader<?>) {
T t = ((AsyncTaskLoader<T>)m_Loader).loadInBackground();
return t;
} else {
synchronized (m_Lock) {
m_Loader.registerListener(0, this);
m_Loader.startLoading();
try {
m_Lock.wait();
} catch (InterruptedException ignored) { }
m_Loader.unregisterListener(this);
return m_Data;
}
}
} finally {
m_Loader.reset(); // leave in a fresh state TODO: this violates the documented contract that onReset() is always called from main thread
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment