fix(tsconnect): address bridge review findings
Co-Authored-By: gpt-5.6-sol <noreply@openai.com>
This commit is contained in:
@@ -246,13 +246,16 @@ func wireTaildropFileOps(lb *ipnlocal.LocalBackend, jsObj js.Value) {
|
||||
// ReadableStreamDefaultReader. Each Read call awaits one reader.read() Promise,
|
||||
// using the channel+FuncOf pattern so Go blocks until JS delivers the chunk.
|
||||
type jsStreamReader struct {
|
||||
mu sync.Mutex
|
||||
reader js.Value
|
||||
buf []byte
|
||||
done bool
|
||||
err error
|
||||
mu sync.Mutex
|
||||
reader js.Value
|
||||
buf []byte
|
||||
done bool
|
||||
err error
|
||||
testCancelTimeout time.Duration
|
||||
}
|
||||
|
||||
const jsStreamCancelTimeout = time.Second
|
||||
|
||||
func (r *jsStreamReader) Read(p []byte) (int, error) {
|
||||
r.mu.Lock()
|
||||
if r.err != nil {
|
||||
@@ -386,8 +389,19 @@ func (r *jsStreamReader) Close() error {
|
||||
if _, err := callJSMethod(promise, "then", resolveFn, rejectFn); err != nil {
|
||||
return r.setError(err)
|
||||
}
|
||||
if err := <-resultCh; err != nil {
|
||||
return r.setError(err)
|
||||
timeout := jsStreamCancelTimeout
|
||||
if r.testCancelTimeout > 0 {
|
||||
timeout = r.testCancelTimeout
|
||||
}
|
||||
timer := time.NewTimer(timeout)
|
||||
defer timer.Stop()
|
||||
select {
|
||||
case err := <-resultCh:
|
||||
if err != nil {
|
||||
return r.setError(err)
|
||||
}
|
||||
case <-timer.C:
|
||||
return r.setError(errors.New("JavaScript stream cancel timed out"))
|
||||
}
|
||||
r.mu.Lock()
|
||||
r.done = true
|
||||
|
||||
Reference in New Issue
Block a user