Commit d792de8b authored by Kyle Clarke's avatar Kyle Clarke

Updated readme for better flow to the reader.

parent 86b67149
Pipeline #6771590 (#) passed with stage
in 29 seconds
......@@ -5,9 +5,23 @@ ___
Qupid is a Queue/Pipeline package written in [Golang](https://golang.org/) that gives helpful accessors to queue, consume, return and halt queue processing.
```
// Install with the usual or add to you package manager of choice.
go get gitlab.com/kylehqcom/qupid
```
### A contrived example
Lets setup a new Qupid Q instance `qupid.WithPipelineBuffer(50)`, create a `NewEntry(ID) *entry` and `Queue(*entry)`, assigning an entity to the entry `WithEntity(ent)`. Then process the entry on the `<-Consume()` channel, and send a `NewResult(*entry) result` to the `Complete(result)` method. After processing for a couple seconds, lets interrupt the Q instance with `Stop()`.
In a normal workflow you might:
1. setup a new Qupid Q instance `qupid.WithPipelineBuffer(50)`
2. create a `NewEntry(ID) *entry` assigning an entity to the entry `WithEntity(ent)`
3. queue up the entry`Queue(*entry)`
4. process the entry on the `<-Consume()` channel
5. send a `NewResult(*entry) result` to the `Complete(result)` method
6. After processing for a couple seconds, lets interrupt the Q instance with `Stop()`
If you have checked out the code, `go run main.go` from the `/example` directory to see Qupid in action.
```
package main
......@@ -28,6 +42,7 @@ func Do() {
for {
select {
case <-t.C:
// Get items to process
ent, err := ToProcess()
if err != nil {
Stop()
......@@ -37,6 +52,7 @@ func Do() {
q.Queue(qupid.NewEntry(ent.ID, qupid.WithEntity(ent)))
case e := <-q.Consume():
// Only one entry will be consumed due to identical ids being passed.
res := qupid.NewResult(e)
ent, ok := e.Entity.(*Ent)
if !ok {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment