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 1 commit
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
69 changes: 46 additions & 23 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("kkk");

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,18 +224,29 @@ 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) -> {
List<String> keys = new ArrayList<>();
keys.add("kkk");
Copy link
Member

@krizzu krizzu Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove those two lines, as they're not used


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("my_key", "my_value");
entries.add(entry);
asyncStorage.setValues(entries, cont);
return Unit.INSTANCE;
});
}
```

Expand Down