Skip to content

Commit ba5c863

Browse files
committed
chore: HTTP runtime yield in pollable
Signed-off-by: Lucas Fontes <[email protected]>
1 parent fbef37e commit ba5c863

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

component/net/wasihttp/roundtripper.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"io"
66
"net/http"
7+
"runtime"
78
"time"
89

910
"go.bytecodealliance.org/cm"
@@ -116,7 +117,10 @@ func (r *Transport) RoundTrip(incomingRequest *http.Request) (*http.Response, er
116117
futureResponse := handleResp.OK()
117118

118119
// wait until resp is returned
119-
futureResponse.Subscribe().Block()
120+
futurePollable := futureResponse.Subscribe()
121+
for !futurePollable.Ready() {
122+
runtime.Gosched()
123+
}
120124

121125
pollableOption := futureResponse.Get()
122126
if pollableOption.None() {

component/net/wasihttp/streams.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8+
"runtime"
89
"sync"
910

1011
"go.bytecodealliance.org/cm"
@@ -87,7 +88,9 @@ func (r *inputStreamReader) parseTrailers() {
8788

8889
func (r *inputStreamReader) Read(p []byte) (n int, err error) {
8990
pollable := r.stream.Subscribe()
90-
pollable.Block()
91+
for !pollable.Ready() {
92+
runtime.Gosched()
93+
}
9194
pollable.ResourceDrop()
9295

9396
readResult := r.stream.Read(uint64(len(p)))

0 commit comments

Comments
 (0)