Skip to content

Commit

Permalink
projections docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hallgren committed Mar 2, 2024
1 parent 22d1bf9 commit f26c18c
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,32 +428,46 @@ A projection can be started in three different ways.
RunOnce fetch events from the event store one time. It returns true if there were events to iterate otherwise false.

```go
RunOnce() (bool, Result)
RunOnce() (bool, ProjectionResult)
```

#### RunToEnd

RunToEnd fetch events from the event store until it reaches the end of the event stream. A context is passed in making it possible to cancel the projections from the outside.

```go
RunToEnd(ctx context.Context) Result
RunToEnd(ctx context.Context) ProjectionResult
```

#### Run

Run will run forever until canceled from the outside. When it hits the end of the event stream it will start a timer and sleep the time set in the projection property `Pace`.

```go
Run(ctx context.Context) Result
Run(ctx context.Context) ProjectionResult
```

All run methods return a ProjectionResult.

```go
type ProjectionResult struct {
Error error
ProjectionName string
Event Event
}
```
* **Error** Is set if the projection returned an error
* **ProjectionName** Is the name of the projection
* **Event** The last fetched event (can be useful during debugging)

### Projection properties

A projection have a set of properties that can affect it's behaivior.

* **Pace** - Is used in the Run method to set how often the projection will poll the event store for new events.
* **Strict** - Default true and it will trigger an error if a fetched event is not registered in the event `Register`. This force all events to be handled by the callbackFunc.
* **Name** - The name of the projection. Can be useful when debugging multiple running projection. The default name is the index it was created from the projection handler.


### Run multiple projections

#### Group
Expand Down Expand Up @@ -495,29 +509,17 @@ select {

#### Race

Compared to a group the race is a one shot operation. Instead of fetching events ontinuously it's used to iterate all existing events and then return.
Compared to a group the race is a one shot operation. Instead of fetching events continuously it's used to iterate and process all existing events and then return.

The `Race()` method starts a set of projections and run them to the end of there event streams.
The `Race()` method starts the projections and run them to the end of there event streams. When all projections are finished the method return.

```go
Race(cancelOnError bool, projections ...*Projection) ([]RaceResult, error)
Race(cancelOnError bool, projections ...*Projection) ([]ProjectionResult, error)
```

If `cancelOnError` is set to true the race will return if any projection is returning an error.

The returned `[]RaceResult` is a slice of structs containg each projections result.

* **Error** Is set if the projection returned an error
* **ProjectionName** Is the name of the projection
* **Event** The last fetched event (can be useful during debugging)
If `cancelOnError` is set to true the method will halt all projections and return if any projection is returning an error.

```go
type RaceResult struct {
Error error
ProjectionName string
Event Event
}
```
The returned `[]ProjectionResult` is a collection of all projection results.

Race example:

Expand Down

0 comments on commit f26c18c

Please sign in to comment.