Explorer

definy.sync-events-loop

description
Sync the events one by one in order
type
Fn(
  sync: Fn(event: @definy.stored-event, then: Fn(error: Union{#none, #some(String)}) -> @definy.service-io) -> @definy.service-io,
  events: List<@definy.stored-event>,
  index: Number,
  count: Number,
  errors: List<String>,
  then: Fn(summary: Record{count: Number, errors: List<String>}) -> @definy.service-io
) -> @definy.service-io
expression
fn(sync$0, events$1, index$2, count$3, errors$4, then$5) =>
  match @core.list-get(list: $1, index: $2) {
    #none(_) =>
      $5(summary: {count: $3, errors: $4}),
    #some(event$6) =>
      $0(
        event: $6,
        then: fn(error$7) =>
          @definy.sync-events-loop(
            sync: fn(event$10, then$11) =>
              $0(
                event: $10,
                then: fn(error$12) =>
                  $11(error: $12)
              ),
            events: $1,
            index: @core.plus(left: $2, right: 1),
            count: match $7 {
              #none(_) =>
                @core.plus(left: $3, right: 1),
              #some(_) =>
                $3
            },
            errors: match $7 {
              #none(_) =>
                $4,
              #some(message$8) =>
                @core.list-append(
                  list: $4,
                  item: @std.string-join(items: [$6.event_type, " ", $6.event_hash, ": ", $8], separator: "")
                )
            },
            then: fn(summary$9) =>
              $5(summary: $9)
          )
      )
  }
visibility
public
definy.sync-events-loop (project definy, branch main, snapshot l0VFjJZP174d8CbZWFoujAGTYjgsQu4uTq5uWCZaXgo)
id: K_47FAGMvJrcJV_t1Wg8wSfsftixBJ9gSJgNvrlZL1w
content hash: RJcM4G73DtqyJw_g1tobY7J1SacoqwICoDFrkAsHAJQ