/**
 * This example demonstrates two services emitting messages to each other.
 */

import goodly from 'goodly';

if(!process.argv[2]) {
  console.log('You must supply the broker path');
  process.exit(1);
}

// ping service
(async () => {
  let rounds = 0;

  const service = goodly({ name: 'example2-ping' });
  await service.start({ brokerPath: process.argv[2] });

  // list to the pong e vent and emit a ping event
  await service.on('pong', async ({ emit }) => {
    if(rounds > 5) return;

    console.log('ping');
    await emit('ping');
    rounds++;
  });

  // start the ping/pong with a ping
  service.emit('ping');

})().catch(console.log);


// pong service
(async () => {

  const service = goodly({ name: 'example2-pong' });
  await service.start({ brokerPath: process.argv[2] });

  // list to the ping e vent and emit a ping event
  await service.on('ping', async ({ emit }) => {
    console.log('pong');
    await emit('pong');
  });

})().catch(console.log);
@@ -381,25 +381,24 @@
 o the pong e
- 
 vent and emi
@@ -813,17 +813,16 @@
 e ping e
- 
 vent and
@@ -822,33 +822,33 @@
 ent and emit a p
-i
+o
 ng event%0A  await
@@ -949,28 +949,29 @@
 );%0A%0A%7D)().catch(console.log);
+%0A

Update comments