Merge pull request #293 from status-im/182-async-await-syntax

This commit is contained in:
Franck Royer 2021-09-15 10:36:25 +10:00 committed by GitHub
commit 1a9ab2ec77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View File

@ -6,6 +6,7 @@
- React/JavaScript
- Waku Relay
- Protobuf using `protons`.
- No async/await syntax.
A barebone chat app to illustrate the [ReactJS Relay guide](/guides/reactjs-relay.md).

View File

@ -95,7 +95,7 @@ function App() {
export default App;
async function sendMessage(message, timestamp, waku) {
function sendMessage(message, timestamp, waku) {
const time = timestamp.getTime();
const payload = proto.SimpleChatMessage.encode({
@ -103,6 +103,7 @@ async function sendMessage(message, timestamp, waku) {
text: message,
});
const wakuMessage = await WakuMessage.fromBytes(payload, ContentTopic);
await waku.relay.send(wakuMessage);
return WakuMessage.fromBytes(payload, ContentTopic).then((wakuMessage) =>
waku.relay.send(wakuMessage)
);
}

View File

@ -3,6 +3,7 @@
- React/JavaScript,
- Waku Store,
- Protobuf using `protons`.
- No async/await syntax.
A simple app that retrieves chat messages using [Waku Store](https://rfc.vac.dev/spec/13/)
to illustrate the [Retrieve Messages Using Waku Store With ReactJS guide](/guides/reactjs-store.md).

View File

@ -133,20 +133,20 @@ import { WakuMessage } from 'js-waku';
const ContentTopic = `/min-react-js-chat/1/chat/proto`;
async function sendMessage(message, timestamp, waku) {
function sendMessage(message, timestamp, waku) {
const time = timestamp.getTime();
// Encode to protobuf
const payload = proto.SimpleChatMessage.encode({
timestamp: time,
text: message,
text: message
});
// Wrap in a Waku Message
const wakuMessage = await WakuMessage.fromBytes(payload, ContentTopic);
// Send over Waku Relay
await waku.relay.send(wakuMessage);
return WakuMessage.fromBytes(payload, ContentTopic).then((wakuMessage) =>
// Send over Waku Relay
waku.relay.send(wakuMessage)
);
}
```