Skip to content

Commit

Permalink
update simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoBrigitte committed Nov 21, 2024
1 parent a9880f5 commit adb5dc1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,28 @@ This Go package provides a map that automatically removes entries after a given
package main

import (
"fmt"
"time"
"fmt"
"time"

"github.com/TheoBrigitte/expirymap"
"github.com/TheoBrigitte/expirymap"
)

func main() {
// Define a key and a value.
key := 1
value := []string{"foo", "bar", "baz"}
// Define a key and a value.
key := 1
value := []string{"foo", "bar", "baz"}

// Create a new map[int]string with an expiry delay of 1ns and a garbage collection interval of 1ms.
m := expirymap.New[int, []string](time.Nanosecond, time.Millisecond)
defer m.Stop()
// Create a new expiry map of type map[int][]string
// with an expiry delay of 1ns and a garbage collection interval of 1ms.
m := expirymap.New[int, []string](time.Nanosecond, time.Millisecond)
defer m.Stop()

// Set 1=[foo bar baz] in the map.
m.Set(key, value)
// Set 1=[foo bar baz] in the map.
m.Set(key, value)

fmt.Println(m.Get(1)) // [foo bar baz]
time.Sleep(time.Millisecond * 2) // Wait for the entry to expire.
fmt.Println(m.Get(1)) // []
fmt.Println(m.Get(1)) // [foo bar baz]
time.Sleep(time.Millisecond * 2) // Wait for the entry to expire.
fmt.Println(m.Get(1)) // []
}
```
source [example/simple/simple.go](./example/simple/simple.go)
3 changes: 2 additions & 1 deletion example/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ func main() {
key := 1
value := []string{"foo", "bar", "baz"}

// Create a new map[int]string with an expiry delay of 1ns and a garbage collection interval of 1ms.
// Create a new expiry map of type map[int][]string
// with an expiry delay of 1ns and a garbage collection interval of 1ms.
m := expirymap.New[int, []string](time.Nanosecond, time.Millisecond)
defer m.Stop()

Expand Down

0 comments on commit adb5dc1

Please sign in to comment.