Skip to content

Commit

Permalink
fix stream conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
syumai committed Apr 20, 2024
1 parent 18c1cd5 commit 175a83e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/jsutil/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (sr *readableStreamToReadCloser) Read(p []byte) (n int, err error) {
sr.streamReader = &r
}
if sr.buf.Len() == 0 {
promise := sr.streamReader.Call("read")
resultCh := make(chan js.Value)
errCh := make(chan error)
promise := sr.streamReader.Call("read")
var then, catch js.Func
then = js.FuncOf(func(_ js.Value, args []js.Value) any {
defer then.Release()
Expand Down Expand Up @@ -167,12 +167,14 @@ func ConvertReaderToReadableStream(reader io.ReadCloser) js.Value {
resolve := pArgs[0]
reject := pArgs[1]
controller := args[0]
err := stream.Pull(controller)
if err != nil {
reject.Invoke(ErrorClass.New(err.Error()))
return js.Undefined()
}
resolve.Invoke()
go func() {
err := stream.Pull(controller)
if err != nil {
reject.Invoke(ErrorClass.New(err.Error()))
return
}
resolve.Invoke()
}()
return js.Undefined()
})
return NewPromise(cb)
Expand Down

0 comments on commit 175a83e

Please sign in to comment.