Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 3cf11ed

Browse files
committed
Do not send on closed channel
Signed-off-by: tzununbekov <[email protected]>
1 parent 513f131 commit 3cf11ed

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,11 @@ func newTask(w http.ResponseWriter, r *http.Request) {
9696
w.WriteHeader(http.StatusRequestTimeout)
9797
w.Write([]byte("Function deadline is reached"))
9898
case result := <-results[task.id]:
99-
fmt.Printf("Response in queue %s\n", result.id)
10099
fmt.Printf("-> %s %s\n", result.id, result.data)
101100
w.WriteHeader(http.StatusOK)
102101
w.Write(result.data)
103102
}
104-
103+
delete(results, task.id)
105104
return
106105
}
107106

@@ -139,6 +138,13 @@ func postResult(w http.ResponseWriter, r *http.Request) {
139138
}
140139
defer r.Body.Close()
141140

141+
if _, ok := results[id]; !ok {
142+
w.WriteHeader(http.StatusGatewayTimeout)
143+
w.Write([]byte("Function deadline is reached"))
144+
return
145+
}
146+
147+
fmt.Println("Channel is open")
142148
results[id] <- message{
143149
id: id,
144150
data: data,

0 commit comments

Comments
 (0)