Examples with no async/await syntax

Useful for those using ClojureScript.

Resolves #182.
This commit is contained in:
Franck Royer 2021-09-07 14:44:20 +10:00
parent 898f93371c
commit a352cb0b38
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
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)
);
}
```