Pond.emit vs Pond.publish

Hi there,

I realized that in Actyx 2.10, emit is marked as deprecated and publish is recommended.
Could anybody give an example on how to use publish? I tried to just replace “emit” with “publish” and it (obviously) did not work.

Thank you!

1 Like

Hi Dipta,

the transition from emit to publish serves two purposes:

  • emit returned a result that was easy to overlook and ignore, possibly leading to event ordering issues — it is recommended practice to always await the result of publishing events
  • emit accepted any kind of tags for any kind of event, whereas the most convenient way of using publish ensures that the types have been declared to match the event in question

The recommended way to publish events has the following steps:

// Declare a tag type, possibly in a shared project or repository.
// This promises to only publish events of type MyEventType with the tag `my-event`
const myTag = Tag<MyEventType>('my-event')

// this is an additional tag that you may want to select events by later
const someOtherTag = Tag('other-tag')

// ... and now for the actual publishing part ...

// compute the tags to apply to an event, possibly adding further ones that
// don’t have an implication on the Typescript type, like to which entity ID
// this event belongs
const tags = myTag.withId(myEntityId).and(someOtherTag)
const event: MyEventType = ...
// the `.apply()` step ensures that the event matches the chosen tags
await pond.publish(tags.apply(event))

With Pond v3.2.3 there are also some new functions that allow you to take the result of tags.applyTyped(event) and add more tags, if you want to split the application of tags across different functions in your code.

I think we’ll need to improve our documentation on the TS SDK and Pond, and until that happens I’m even happier to answer your questions here!



1 Like

Yes, I agree that the await is a very important thing here.
And I can confirm that the example works!

Thank you, Roland!

1 Like

You’re very welcome!