This commit is contained in:
bluepython508 committed 2026-10-22 12:27:19 +01:00
1 parent 3530afb854
commit 6903fcff27
2146 files changed
+112256 -190703

No files matched your search

+5 -4
View File
@@ -5,15 +5,16 @@ import (
"sync"
)
var bpool sync.Pool
var bpool = sync.Pool{
New: func() any {
return &bytes.Buffer{}
},
}
// Get returns a buffer from the pool or creates a new one if
// the pool is empty.
func Get() *bytes.Buffer {
b := bpool.Get()
if b == nil {
return &bytes.Buffer{}
}
return b.(*bytes.Buffer)
}
+1 -1
View File
@@ -7,7 +7,7 @@ import (
// Wrap wraps err with fmt.Errorf if err is non nil.
// Intended for use with defer and a named error return.
// Inspired by https://github.com/golang/go/issues/32676.
func Wrap(err *error, f string, v ...interface{}) {
func Wrap(err *error, f string, v ...any) {
if *err != nil {
*err = fmt.Errorf(f+": %w", append(v, *err)...)
}
+4 -4
View File
@@ -33,7 +33,7 @@ func New(url string, protocols []string) (c WebSocket, err error) {
c = WebSocket{}
})
jsProtocols := make([]interface{}, len(protocols))
jsProtocols := make([]any, len(protocols))
for i, p := range protocols {
jsProtocols[i] = p
}
@@ -57,7 +57,7 @@ func (c WebSocket) setBinaryType(typ string) {
}
func (c WebSocket) addEventListener(eventType string, fn func(e js.Value)) func() {
f := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
f := js.FuncOf(func(this js.Value, args []js.Value) any {
fn(args[0])
return nil
})
@@ -97,7 +97,7 @@ func (c WebSocket) OnError(fn func(e js.Value)) (remove func()) {
// MessageEvent is the type passed to a message handler.
type MessageEvent struct {
// string or []byte.
Data interface{}
Data any
// There are more fields to the interface but we don't use them.
// See https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent
@@ -106,7 +106,7 @@ type MessageEvent struct {
// OnMessage registers a function to be called when the WebSocket receives a message.
func (c WebSocket) OnMessage(fn func(m MessageEvent)) (remove func()) {
return c.addEventListener("message", func(e js.Value) {
var data interface{}
var data any
arrayBuffer := e.Get("data")
if arrayBuffer.Type() == js.TypeString {
-26
View File
@@ -1,26 +0,0 @@
package xsync
import (
"fmt"
"runtime/debug"
)
// Go allows running a function in another goroutine
// and waiting for its error.
func Go(fn func() error) <-chan error {
errs := make(chan error, 1)
go func() {
defer func() {
r := recover()
if r != nil {
select {
case errs <- fmt.Errorf("panic in go fn: %v, %s", r, debug.Stack()):
default:
}
}
}()
errs <- fn()
}()
return errs
}
-23
View File
@@ -1,23 +0,0 @@
package xsync
import (
"sync/atomic"
)
// Int64 represents an atomic int64.
type Int64 struct {
// We do not use atomic.Load/StoreInt64 since it does not
// work on 32 bit computers but we need 64 bit integers.
i atomic.Value
}
// Load loads the int64.
func (v *Int64) Load() int64 {
i, _ := v.i.Load().(int64)
return i
}
// Store stores the int64.
func (v *Int64) Store(i int64) {
v.i.Store(i)
}