Skip to content

Commit

Permalink
Add few comments for PR Review
Browse files Browse the repository at this point in the history
  • Loading branch information
Eroui authored and chermehdi committed Jan 10, 2021
1 parent b43a316 commit d92b1f8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions commands/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

const listenAddr = ":4243"

// TaskExistsError is an rror indicating the task directory exists. Used to be able to skip task creation and move the next one when parsing a contest.
var TaskExistsError = errors.New("Task already exists, creation skipped!")

// Serialize task into a JSON string.
Expand Down Expand Up @@ -138,6 +139,8 @@ func createWebServer(quit chan<- string) *http.Server {

func waitForShutDown(server *http.Server, done chan<- string, quit <-chan string, problemsCount int) {

// readProblems is a function that waits for problemsCount problems json to be sent to the server and push them to the consumer.
// Also to be able to close producer and consumer channels one all problems are read (Or timed out).
readProblems := func() <-chan string {
results := make(chan string, problemsCount)
defer close(results)
Expand All @@ -161,13 +164,15 @@ func waitForShutDown(server *http.Server, done chan<- string, quit <-chan string
return results
}

// function to consume list of all received problems and then close the channel.
consumeProblems := func(results <-chan string) {
defer close(done)
for result := range results {
done <- result
}
}

// Receive and consume the list of all problems and close the channels
problems := readProblems()
consumeProblems(problems)

Expand Down

0 comments on commit d92b1f8

Please sign in to comment.