Fixed the close() functions, also ignore the last commit message i messed it up :3

This commit is contained in:
Tracker-Friendly 2024-10-28 10:10:57 +00:00
parent 47970e0051
commit a05d2cae18
2 changed files with 16 additions and 4 deletions

12
main.go
View File

@ -67,8 +67,10 @@ func (r *ReadableStream) Close() (err error) {
defer func() {
// We don't want any errors to be thrown if the stream is already closed.
recovery := recover()
if !strings.Contains(recovery.(string), "Can not close stream after closing or error") {
err = fmt.Errorf("panic: %v", recovery)
if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") {
if recovery != nil {
err = fmt.Errorf("panic: %v", recovery)
}
}
}()
@ -141,8 +143,10 @@ func (w *WritableStream) Close() (err error) {
defer func() {
// We don't want any errors to be thrown if the stream is already closed.
recovery := recover()
if !strings.Contains(recovery.(string), "Can not close stream after closing or error") {
err = fmt.Errorf("panic: %v", recovery)
if !strings.Contains(fmt.Sprint(recovery), "Can not close stream after closing or error") {
if recovery != nil {
err = fmt.Errorf("panic: %v", recovery)
}
}
}()

View File

@ -21,6 +21,10 @@ func main() {
return
}
fmt.Println(string(buffer))
err = readStream.Close()
if err != nil {
fmt.Println(err)
}
}()
return nil
@ -34,6 +38,10 @@ func main() {
fmt.Println(err)
return
}
err = writeStream.Close()
if err != nil {
fmt.Println(err)
}
}()
return nil