Comments (1)
I thought about modifying the logic like this, but since I can't think of a use case I want to use it for, I'll leave it as is for now.
index 79aed80..e602892 100644
--- a/period.go
+++ b/period.go
@@ -2,6 +2,8 @@ package synchro
import (
"fmt"
+ "runtime"
+ "sync"
"time"
"unsafe"
@@ -69,11 +71,16 @@ func (p Period[T]) Contains(t Time[T]) int {
type periodical[T TimeZone] <-chan Time[T]
+var pCache sync.Map
+
// Slice returns the slice of Time[T].
func (p periodical[T]) Slice() (s []Time[T]) {
for current := range p {
s = append(s, current)
}
+ if cache, ok := pCache.LoadOrStore(p, s); ok {
+ return cache.([]Time[T])
+ }
return s
}
@@ -99,9 +106,15 @@ func (p Period[T]) Periodic(next func(Time[T]) Time[T]) periodical[T] {
ch <- current
}
}()
+ runtime.SetFinalizer(&ch, func(ch *chan Time[T]) {
+ pCache.Delete(*ch)
+ })
return ch
}
func isNotAfter[T TimeZone](t1, t2 Time[T]) bool {
// t1.Compare(t2) <= 0
return !t1.After(t2)
diff --git a/period_test.go b/period_test.go
index dbb0bd8..35bc27f 100644
--- a/period_test.go
+++ b/period_test.go
@@ -2,6 +2,7 @@ package synchro
from synchro.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from synchro.