vertx-eventbus-bridge-clients icon indicating copy to clipboard operation
vertx-eventbus-bridge-clients copied to clipboard

model eventbus

Open Ako-Njang opened this issue 2 years ago • 4 comments

@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 avatar Apr 15 '22 16:04 Ako-Njang

@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.

pmlopes avatar Apr 19 '22 08:04 pmlopes

@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.

Ako-Njang avatar Apr 19 '22 08:04 Ako-Njang

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...
   });

pmlopes avatar Apr 22 '22 18:04 pmlopes

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>

Ako-Njang avatar Jun 07 '22 23:06 Ako-Njang