vertx-eventbus-bridge-clients
vertx-eventbus-bridge-clients copied to clipboard
model eventbus
@pmlopes here is simple modeling of the EventBus object I did. I also did some refactoring to suit ES6 with respect to variables and function declarations. While working on creating promises to replace the callbacks can you have any suggestions?
@Ako-Njang thank you, this is a great start.
I think you can keep improving this even further:
For example, all functions that have a final argument: callback
, could be transformed to a promise like function. Let me illustrate:
// original
function someFunction(a, b, callback) {
// some code
if (success)
callback(null, result);
} else {
callback(error);
}
}
Can be transformed to:
// original
function someFunction(a, b) {
return new Promise(onSuccess, onFailure) => {
// some code
if (success)
onSuccess(result);
} else {
onFailure(error);
}
});
}
This means that later users can use this new API as:
let reply = await eventBus.send(x, y);
As the return of the function is a promise users can write simpler code with async/await (or if they need to support older browsers), then chaining promises is also possible and still more readable than the older callback style.
@Ako-Njang thank you, this is a great start.
I think you can keep improving this even further:
For example, all functions that have a final argument:
callback
, could be transformed to a promise like function. Let me illustrate:// original function someFunction(a, b, callback) { // some code if (success) callback(null, result); } else { callback(error); } }
Can be transformed to:
// original function someFunction(a, b) { return new Promise(onSuccess, onFailure) => { // some code if (success) onSuccess(result); } else { onFailure(error); } }); }
This means that later users can use this new API as:
let reply = await eventBus.send(x, y);
As the return of the function is a promise users can write simpler code with async/await (or if they need to support older browsers), then chaining promises is also possible and still more readable than the older callback style.
Thank you for this. I was a little confused about how the promises would be used. I will keep in mind the promises are for users who will install the library later in their projects. Thanks for clearing my doubts. I will begin this phase. I appreciate the feedback.
Yes, promises can be used with any browser (except really old ones or IE10) but those don't support webrtc either.
Old browsers may not support the async / await
style but as Promises are supported they work like this:
// new browser:
let reply = await eventBus.send(a, b);
// older (on the same code)
eventBus.send(a, b)
.then(reply => {
// code that uses the reply...
});
This week ( 06 - 10/06/2022 )
- Understand the core functionality and interfaces that webRTC provides and how to implement.
- Went through code proposed and ran it successfully
- Will try to implement an example myself to make sure I understand the concepts
- Understand the core functionality Vert.x Event bus provides so that I can work on preserving them..
- Advance with my blogpost
Next week (13 - 17/06/2022)
- Come out with a design on how to map features of the Event bus to the corresponding webRTC feature.
- Begin work on implementing the javaScript Event bus with webRTC as the required library.
- Work on mentor feedback.
- Advance with my blog post
Message ID: <vert-x3/vertx-eventbus-bridge-clients/pull/69/c1106751098@
github.com>