Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
2cf571579b
|
|||
9a537bb8c2
|
|||
78ad103151
|
@@ -9,6 +9,12 @@ import (
|
|||||||
"git.blackforestbytes.com/BlackForestBytes/goext/syncext"
|
"git.blackforestbytes.com/BlackForestBytes/goext/syncext"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DelayedCombiningInvoker is a utility to combine multiple consecutive requests into a single execution
|
||||||
|
//
|
||||||
|
// Requests are made with Request(), and consecutive requests are combined during the `delay` period.
|
||||||
|
//
|
||||||
|
// Can be used, e.g., for search-controls, where we want to init the search when teh user stops typing
|
||||||
|
// Or generally to queue an execution once a burst of requests is over.
|
||||||
type DelayedCombiningInvoker struct {
|
type DelayedCombiningInvoker struct {
|
||||||
syncLock sync.Mutex
|
syncLock sync.Mutex
|
||||||
triggerChan chan bool
|
triggerChan chan bool
|
||||||
@@ -79,10 +85,14 @@ func (d *DelayedCombiningInvoker) Request() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DelayedCombiningInvoker) run() {
|
func (d *DelayedCombiningInvoker) run() {
|
||||||
|
|
||||||
|
needsExecutorRunningCleanup := true
|
||||||
defer func() {
|
defer func() {
|
||||||
d.syncLock.Lock()
|
if needsExecutorRunningCleanup {
|
||||||
d.executorRunning.Set(false)
|
d.syncLock.Lock()
|
||||||
d.syncLock.Unlock()
|
d.executorRunning.Set(false)
|
||||||
|
d.syncLock.Unlock()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@@ -129,6 +139,9 @@ func (d *DelayedCombiningInvoker) run() {
|
|||||||
_ = langext.RunPanicSafe(d.action)
|
_ = langext.RunPanicSafe(d.action)
|
||||||
// =================================================
|
// =================================================
|
||||||
|
|
||||||
|
d.executorRunning.Set(false) // ensure HasPendingRequests returns fals ein onExecutionDone listener
|
||||||
|
needsExecutorRunningCleanup = false
|
||||||
|
|
||||||
for _, fn := range d.onExecutionDone {
|
for _, fn := range d.onExecutionDone {
|
||||||
_ = langext.RunPanicSafe(fn)
|
_ = langext.RunPanicSafe(fn)
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@@ -48,7 +48,7 @@ require (
|
|||||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
|
||||||
github.com/quic-go/qpack v0.5.1 // indirect
|
github.com/quic-go/qpack v0.5.1 // indirect
|
||||||
github.com/quic-go/quic-go v0.54.0 // indirect
|
github.com/quic-go/quic-go v0.54.1 // indirect
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||||
github.com/ugorji/go/codec v1.3.0 // indirect
|
github.com/ugorji/go/codec v1.3.0 // indirect
|
||||||
|
2
go.sum
2
go.sum
@@ -183,6 +183,8 @@ github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI=
|
|||||||
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg=
|
||||||
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
|
github.com/quic-go/quic-go v0.54.0 h1:6s1YB9QotYI6Ospeiguknbp2Znb/jZYjZLRXn9kMQBg=
|
||||||
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
github.com/quic-go/quic-go v0.54.0/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
||||||
|
github.com/quic-go/quic-go v0.54.1 h1:4ZAWm0AhCb6+hE+l5Q1NAL0iRn/ZrMwqHRGQiFwj2eg=
|
||||||
|
github.com/quic-go/quic-go v0.54.1/go.mod h1:e68ZEaCdyviluZmy44P6Iey98v/Wfz6HCjQEm+l8zTY=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.602"
|
const GoextVersion = "0.0.605"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2025-09-20T15:13:02+0200"
|
const GoextVersionTimestamp = "2025-09-29T16:39:16+0200"
|
||||||
|
@@ -27,11 +27,11 @@ func (r GoJsonRender) Render(w http.ResponseWriter) error {
|
|||||||
}
|
}
|
||||||
jsonBytes, err := MarshalSafeCollections(r.Data, r.NilSafeSlices, r.NilSafeMaps, r.Indent, r.Filter)
|
jsonBytes, err := MarshalSafeCollections(r.Data, r.NilSafeSlices, r.NilSafeMaps, r.Indent, r.Filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
_, err = w.Write(jsonBytes)
|
_, err = w.Write(jsonBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ func (r GoJsonRender) Render(w http.ResponseWriter) error {
|
|||||||
func (r GoJsonRender) RenderString() (string, error) {
|
func (r GoJsonRender) RenderString() (string, error) {
|
||||||
jsonBytes, err := MarshalSafeCollections(r.Data, r.NilSafeSlices, r.NilSafeMaps, r.Indent, r.Filter)
|
jsonBytes, err := MarshalSafeCollections(r.Data, r.NilSafeSlices, r.NilSafeMaps, r.Indent, r.Filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return "", err
|
||||||
}
|
}
|
||||||
return string(jsonBytes), nil
|
return string(jsonBytes), nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user