You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+44-24Lines changed: 44 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,35 +12,49 @@ No external dependencies for this package.
12
12
13
13
Create a new Semaphore instance by supplying the capacity of the number of Goroutines you wish to run concurrently and information about the GraphQL point balance.
14
14
15
-
`Aquire(ctx context.Context)` accepts a context which will return an error, if one has happened such as a context timeout.
15
+
The two key methods are:
16
16
17
-
`Release(pts int32)` accepts an integer representing the remaining point balance returned by Shopify's GraphQL API response.
17
+
*`Aquire(ctx context.Context)` which accepts a context which will return an error, if one has happened (such as a context timeout).
18
+
*`Release(pts int32)` which accepts an integer representing the remaining point balance returned by Shopify's GraphQL API response.
18
19
19
20
Example usage:
20
21
21
22
```go
22
23
package main
23
24
24
-
import ssem "github.com/gniktr/shopifysemaphore"
25
+
import (
26
+
"log"
27
+
ssem "github.com/gniktr/shopifysemaphore"
28
+
)
25
29
26
30
funcwork(idint, wg *sync.WaitGroup, ctxcontext.Context, sem *ssem.Semaphore) {
27
31
err:= sem.Aquire(ctx)
28
32
if err != nil {
29
-
// Context timeout.
33
+
// Possible context timeout.
34
+
log.Printf("work: %w", err)
30
35
wg.Done()
31
36
return
32
37
}
33
38
34
-
points, err:=graphQLCall() // Return remaining points from call.
39
+
// Return remaining points from call.
40
+
points, err:=graphQLCall()
35
41
if err != nil {
36
-
// Handle error.
42
+
log.Printf("work: %w", err)
43
+
44
+
// If error is a network error or bad request for example, essentially
45
+
// any error which would cause the response to *not* return point information,
46
+
// then you should set the points to ErrPts to not trigger a point
0 commit comments