Skip to content

Commit

Permalink
implements goroutines for parallel tasking
Browse files Browse the repository at this point in the history
Signed-off-by: Vivek Kumar Sahu <[email protected]>
  • Loading branch information
viveksahu26 committed Jul 2, 2024
1 parent 79f643b commit 57ec133
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions pkg/compliance/cra.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,36 @@ func craResult(ctx context.Context, doc sbom.Document, fileName string, outForma

db := newDB()

db.addRecord(craSpec(doc))
db.addRecord(craSpecVersion(doc))
db.addRecord(craBuildPhase(doc))
db.addRecord(craSbomDepth(doc))
db.addRecord(craCreator(doc))
db.addRecord(craTimestamp(doc))
db.addRecord(craSbomURI(doc))
db.addRecords(craComponents(doc))
// Channel to synchronize goroutines
done := make(chan struct{})

// Function to add a record and sends a completeion signal to channel
addRecordAsync := func(record *record) {
db.addRecord(record)
done <- struct{}{}
}

// Function to add multiple records and signal completion
addRecordsAsync := func(records []*record) {
db.addRecords(records)
done <- struct{}{}
}

// Start goroutines for each record addition
go addRecordAsync(craSpec(doc))
go addRecordAsync(craSpecVersion(doc))
go addRecordAsync(craBuildPhase(doc))
go addRecordAsync(craSbomDepth(doc))
go addRecordAsync(craCreator(doc))
go addRecordAsync(craTimestamp(doc))
go addRecordAsync(craSbomURI(doc))
go addRecordsAsync(craComponents(doc))

// Wait for all goroutines to finish
for i := 0; i < 8; i++ {
// recieve signal
<-done
}

if outFormat == "json" {
craJsonReport(db, fileName)
Expand Down

0 comments on commit 57ec133

Please sign in to comment.