Skip to content

Commit

Permalink
Wrap chanel result logic in LatchResult
Browse files Browse the repository at this point in the history
  • Loading branch information
kroikie committed Sep 4, 2019
1 parent 0834c14 commit 3fe9656
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,7 @@ private static void executeDartCallbackInBackgroundIsolate(
// If another thread is waiting, then wake that thread when the callback returns a result.
MethodChannel.Result result = null;
if (latch != null) {
result =
new MethodChannel.Result() {
@Override
public void success(Object result) {
latch.countDown();
}

@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
latch.countDown();
}

@Override
public void notImplemented() {
latch.countDown();
}
};
result = new LatchResult(latch).getResult();
}

Map<String, Object> args = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.flutter.plugins.firebasemessaging;

import java.util.concurrent.CountDownLatch;

import io.flutter.plugin.common.MethodChannel;

public class LatchResult {

private MethodChannel.Result result;

public LatchResult(final CountDownLatch latch) {
result = new MethodChannel.Result() {
@Override
public void success(Object result) {
latch.countDown();
}

@Override
public void error(String errorCode, String errorMessage, Object errorDetails) {
latch.countDown();
}

@Override
public void notImplemented() {
latch.countDown();
}
};
}

public MethodChannel.Result getResult() {
return result;
}


}

0 comments on commit 3fe9656

Please sign in to comment.