Skip to content

Update Java example for Brownfield integration #583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 43 additions & 25 deletions website/docs/advanced/BrownfieldIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,29 @@ void readStorageValue(Context ctx, String key) {
AsyncStorageAccess asyncStorage = StorageModule.getStorageInstance(ctx);

BuildersKt.launch(GlobalScope.INSTANCE,
Dispatchers.getIO(),
CoroutineStart.DEFAULT,
(scope, continuation) -> {
List<String> keys = new ArrayList<>();
keys.add(key);

List<Entry> entries = (List<Entry>) asyncStorage.getValues(keys, (Continuation<? super List<? extends Entry>>) continuation);
doSomethingWithValues(entries);

return Unit.INSTANCE;
});
Dispatchers.getIO(),
CoroutineStart.DEFAULT,
(scope, continuation) -> {
List<String> keys = new ArrayList<>();
keys.add(key);

Continuation<? super List<? extends Entry>> cont = new Continuation() {
@NotNull
@Override
public CoroutineContext getContext() {
return scope.getCoroutineContext();
}

@Override
public void resumeWith(@NotNull Object o) {
List<Entry> entries = (List<Entry>) o;
doSomethingWithEntries(entries);
}
};

asyncStorage.getValues(keys, cont);
return Unit.INSTANCE;
});

}
```
Expand All @@ -212,20 +224,26 @@ void saveStorageValue(Context ctx, String key, String value) {
AsyncStorageAccess asyncStorage = StorageModule.getStorageInstance(ctx);

BuildersKt.launch(GlobalScope.INSTANCE,
Dispatchers.getIO(),
CoroutineStart.DEFAULT,
(scope, continuation) -> {

List<Entry> entries = new ArrayList<>();
Entry entry = new Entry(key, value);
entries.add(entry);

asyncStorage.setValues(entries, continuation);

return Unit.INSTANCE;
});
Dispatchers.getIO(),
CoroutineStart.DEFAULT,
(scope, continuation) -> {
Continuation cont = new Continuation() {
@NotNull
@Override
public CoroutineContext getContext() {
return scope.getCoroutineContext();
}

@Override
public void resumeWith(@NotNull Object o) {}
};

List<Entry> entries = new ArrayList<>();
Entry entry = new Entry(key, value);
entries.add(entry);
asyncStorage.setValues(entries, cont);
return Unit.INSTANCE;
});
}
```