Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Update events.md to include reference to createEventBuilder #3526

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DianomiJH
Copy link

I couldn't find any reference to createEventBuilder anywhere in the docs site, and it took me spelunking in the Console repo to find out what i was missing creating Events

I don't really know the full ins and outs of how createEventBuilder worked so i added it as an example here rather than give a full section for it.

Copy link

changeset-bot bot commented Nov 23, 2023

⚠️ No Changeset found

Latest commit: 77dc2b4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@fwang fwang requested a review from thdxr November 23, 2023 18:00
@DianomiJH
Copy link
Author

DianomiJH commented Nov 24, 2023

Also, while i'm here, we seem to have found a weird edge case here when trying to publish multiple events in a Promise.all, see the discussion on discord. but it breaks down to creating the payload inside the async loop sends the same payload each time, but creating the payload and then looping to publish works fine and sends separate payloads.

// This example ends up executing the event handler lambda function 3 times with the same payload

async function publishEvent () {
  await Events.Created.publish({
    id: crypto.randomUUID()
  })
}

export async function produceEvents () {
  await Promise.all([
    publishEvent(),
    publishEvent(),
    publishEvent()
  ])
}

whereas this example works:

// this example works as expected, where the event handler lambda function runs 3 times, but each time with a different event

async function publishEvent (eventPayload) {
  await Events.Created.publish(eventPayload)
}

export async function produceEvents () {

  const eventPayloads = [
    { id: crypto.randomUUID() },
    { id: crypto.randomUUID() },
    { id: crypto.randomUUID() },
  ]

  await Promise.all(eventPayloads.map(payload => publishEvent(payload)))
}

thanks to @srodriki for helping identify the issue

@srodriki thought this was unlikely to be a SST issue, but i thought it might be nice to add a warning somewhere in this doc (or perhaps somewhere else?) explaining the edge case and how to avoid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants