Commit 5a71daf7 authored by Cloud User's avatar Cloud User

http api expires

parent 046f8f6a
......@@ -2,8 +2,11 @@ package main
import (
"sync"
"time"
pbUpstream "github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1"
"github.com/hashicorp/golang-lru/v2/expirable"
)
type apiQueryTxsForAddr struct {
......@@ -47,7 +50,8 @@ func callbackRes(res pbUpstream.TaskResponse) {
if !resAsV.async {
resAsV.res <- res
} else {
asyncmap.Store(res.TaskId, res)
asyncmap.Add(res.TaskId, res)
//asyncmap.Store(res.TaskId, res)
}
}
}
......@@ -55,18 +59,25 @@ func callbackRes(res pbUpstream.TaskResponse) {
func getAsyncRes(uuid string) (pbUpstream.TaskResponse, bool) {
if v, ok := asyncmap.LoadAndDelete(uuid); ok {
if resAsV, ok := v.(pbUpstream.TaskResponse); ok {
return resAsV, true
}
}
return asyncmap.Get(uuid)
// if v, ok := asyncmap.LoadAndDelete(uuid); ok {
// if resAsV, ok := v.(pbUpstream.TaskResponse); ok {
// return resAsV, true
// }
// }
return pbUpstream.TaskResponse{}, false
// return pbUpstream.TaskResponse{}, false
}
var recordmap sync.Map
var asyncmap sync.Map
var asyncmap *expirable.LRU[string, pbUpstream.TaskResponse]
func init() {
asyncmap = expirable.NewLRU[string, pbUpstream.TaskResponse](10000, nil, time.Hour*1)
}
func recordUUID() {
for message := range ApiQueryTxsByAddrForQueue {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment