Last active
August 5, 2019 14:10
-
-
Save talfco/ee99c535b719f07bff03806f76f797a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void run1(String endPoint) { | |
WsProvider wsProvider = new WsProvider(endPoint); | |
Promise<ApiPromise> ready = ApiPromise.create(wsProvider); | |
IRpcFunction.Unsubscribe<Promise> unsubscribeHandler = null; | |
ready.then( (ApiPromise api) -> { | |
Promise<IRpcFunction.Unsubscribe<Promise>> invoke = api.rpc().chain().function("subscribeNewHead").invoke( | |
(IRpcFunction.SubscribeCallback<Header>) (Header header) -> | |
{ | |
System.out.println("Chain is at block: " + header.getBlockNumber()+" trigger "+count); | |
count++; | |
if (count >5) { | |
unsubscribeHandler.unsubscribe(); | |
} | |
}); | |
return invoke; | |
}).then((IRpcFunction.Unsubscribe<Promise> result) -> { | |
// Results in compile error: "Variable used in lambda expression should be final or effectively final | |
unsubscribeHandler =result; | |
return null; | |
})._catch((err) -> { | |
err.printStackTrace(); | |
return Promise.value(err); | |
}); | |
try { | |
Thread.sleep(20000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This results in a compile error on line 19. A local variable out-of-scope of the lambda expression must be final.