@@ -6,34 +6,35 @@ import (
66 "log"
77)
88
9- func getItems (tableName string ) ([]map [string ]* dynamodb.AttributeValue , error ) {
9+ func getItemsGoroutine (tableName string ) chan []map [string ]* dynamodb.AttributeValue {
10+ yield := make (chan []map [string ]* dynamodb.AttributeValue )
1011
11- var scannedItems []map [string ]* dynamodb.AttributeValue
12-
13- scanInput := & dynamodb.ScanInput {
14- TableName : aws .String (tableName ),
15- }
12+ go func () {
13+ scanInput := & dynamodb.ScanInput {
14+ TableName : aws .String (tableName ),
15+ }
1616
17- for {
18- log .Println ("Scanning items" )
17+ for {
18+ log .Println ("Scanning items" )
1919
20- scanOutput , err := dynamoService .Scan (scanInput )
21- if err != nil {
22- log .Println ("Failed to scan the items" )
23- return nil , err
24- }
20+ scanOutput , err := dynamoService .Scan (scanInput )
21+ if err != nil {
22+ log .Println ("Failed to scan the items" )
23+ break
24+ }
2525
26- scannedItems = append ( scannedItems , scanOutput .Items ... )
26+ yield <- scanOutput .Items
2727
28- if scanOutput .LastEvaluatedKey != nil && len (scanOutput .LastEvaluatedKey ) > 0 {
29- //there are still items to scan, the the key to start scanning from again
30- scanInput .ExclusiveStartKey = scanOutput .LastEvaluatedKey
31- } else {
32- //no more items to scan, break out
33- break
28+ if scanOutput .LastEvaluatedKey != nil && len (scanOutput .LastEvaluatedKey ) > 0 {
29+ //there are still items to scan, the the key to start scanning from again
30+ scanInput .ExclusiveStartKey = scanOutput .LastEvaluatedKey
31+ } else {
32+ //no more items to scan, break out
33+ break
34+ }
3435 }
35- }
36+ close (yield )
37+ }()
3638
37- return scannedItems , nil
39+ return yield
3840}
39-
0 commit comments