go.temporal.io/server/common/collection/oncemap.go

84 LOC · 24 covered · 60 uncovered · 4 ranges · 81 concepts · 3 introducers · 19 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filego.temporal.io/server/common/cluster/frontend_http_client.go · 109 LOCcluster/frontend_http_cl…workflow_handler.go ×11 · 117 introduced LOCworkflow_handler.go ×11common.go ×1 · 11 introduced LOCcommon.go ×1request_response.pb.go ×6 · 246 introduced LOCrequest_response.pb.go ×…visibility_store.go ×17 · 171 introduced LOCvisibility_store.go ×17telemetry.go ×2 · 15 introduced LOCtelemetry.go ×2fx.go ×1 · 4 introduced LOCfx.go ×1collector.go ×7 · 33 introduced LOCcollector.go ×7data_store_factory.go ×29 · 703 introduced LOCdata_store_factory.go ×2…TestNewServer · 0 introduced LOCTestNewServerpri_matcher.go ×1 · 2 introduced LOCpri_matcher.go ×1timer_queue_active_task_executor.go ×1 · 3 introduced LOCtimer_queue_active_task_…TestNewServer · 0 introduced LOCTestNewServermetric_client.go ×3 · 18 introduced LOCmetric_client.go ×3request_response.pb.go ×12 · 137 introduced LOCrequest_response.pb.go ×…workflow_task_completed_handler.go ×9 · 75 introduced LOCworkflow_task_completed_…pri_forwarder.go ×2 · 4 introduced LOCpri_forwarder.go ×2request_response.pb.go ×1 · 7 introduced LOCrequest_response.pb.go ×…logger.go ×1 · 5 introduced LOClogger.go ×1connections.go ×1 · 9 introduced LOCconnections.go ×1persistence_rate_limited_clients.go ×2 · 17 introduced LOCpersistence_rate_limited…logger.go ×1 · 2 introduced LOClogger.go ×1metric_client.go ×2 · 7 introduced LOCmetric_client.go ×2pri_matcher.go ×1 · 4 introduced LOCpri_matcher.go ×1task_queue_partition_manager.go ×2 · 10 introduced LOCtask_queue_partition_man…connections.go ×2 · 12 introduced LOCconnections.go ×2workflow_handler.go ×8 · 144 introduced LOCworkflow_handler.go ×8pri_matcher.go ×1 · 2 introduced LOCpri_matcher.go ×1handler.go ×1 · 20 introduced LOChandler.go ×1pri_matcher.go ×8 · 55 introduced LOCpri_matcher.go ×8matching_engine.go ×1 · 8 introduced LOCmatching_engine.go ×1server.go ×1 · 3 introduced LOCserver.go ×1logger.go ×2 · 21 introduced LOClogger.go ×2queue_scheduled.go ×1 · 2 introduced LOCqueue_scheduled.go ×1handler.go ×25 · 728 introduced LOChandler.go ×25onebox.go ×75 · 1256 introduced LOConebox.go ×75metric_client_gen.go ×4 · 50 introduced LOCmetric_client_gen.go ×4pri_forwarder.go ×1 · 6 introduced LOCpri_forwarder.go ×1matching_service_server_gen.go ×1 · 2 introduced LOCmatching_service_server_…http_api_server.go ×23 · 195 introduced LOChttp_api_server.go ×23db.go ×1 · 2 introduced LOCdb.go ×1pri_task_writer.go ×3 · 14 introduced LOCpri_task_writer.go ×3namespace_handover.go ×3 · 8 introduced LOCnamespace_handover.go ×3task_queue_partition_manager.go ×2 · 4 introduced LOCtask_queue_partition_man…matching_engine.go ×3 · 5 introduced LOCmatching_engine.go ×3service_grpc.pb.go ×19 · 357 introduced LOCservice_grpc.pb.go ×19request_response.pb.go ×6 · 114 introduced LOCrequest_response.pb.go ×…reader.go ×2 · 8 introduced LOCreader.go ×2service_grpc.pb.go ×20 · 740 introduced LOCservice_grpc.pb.go ×20endpoint_registry.go ×2 · 26 introduced LOCendpoint_registry.go ×2server.go ×3 · 13 introduced LOCserver.go ×3scanner.go ×1 · 2 introduced LOCscanner.go ×1mask_internal_error.go ×1 · 2 introduced LOCmask_internal_error.go ×…matching_engine.go ×2 · 5 introduced LOCmatching_engine.go ×2service_resolver.go ×4 · 49 introduced LOCservice_resolver.go ×4lite_server.go ×25 · 303 introduced LOClite_server.go ×25fx.go ×44 · 705 introduced LOCfx.go ×44adaptive_pool.go ×1 · 3 introduced LOCadaptive_pool.go ×1queue_immediate.go ×1 · 1 introduced LOCqueue_immediate.go ×1fx.go ×1 · 1 introduced LOCfx.go ×1service.go ×8 · 413 introduced LOCservice.go ×8rpc.go ×1 · 13 introduced LOCrpc.go ×1queue_scheduled.go ×1 · 1 introduced LOCqueue_scheduled.go ×1fx.go ×1 · 2 introduced LOCfx.go ×1fx.go ×44 · 4693 introduced LOCfx.go ×44outbound_queue_factory.go ×8 · 144 introduced LOCoutbound_queue_factory.g…rate_limited_scheduler.go ×3 · 7 introduced LOCrate_limited_scheduler.g…queue_immediate.go ×4 · 14 introduced LOCqueue_immediate.go ×4queue_immediate.go ×11 · 166 introduced LOCqueue_immediate.go ×11Archival_enabled · 0 introduced LOCArchival_enabledArchival_disabled · 0 introduced LOCArchival_disabledqueue_factory_base.go ×1 · 2 introduced LOCqueue_factory_base.go ×1ownership_based_quota_calculator.go ×6 · 225 introduced LOCownership_based_quota_ca…outbound_queue_factory.go ×4 · 33 introduced LOCoutbound_queue_factory.g…request.go ×1 · 4 introduced LOCrequest.go ×1request.go ×1 · 2 introduced LOCrequest.go ×1HSM · 0 introduced LOCHSMrequest.go ×1 · 4 introduced LOCrequest.go ×1metadata_mock.go ×2 · 8 introduced LOCmetadata_mock.go ×2frontend_http_client.go ×1 · 15 introduced LOCfrontend_http_client.go …oncemap.go ×2 · 12 introduced LOConcemap.go ×2oncemap.go ×1 · 6 introduced LOConcemap.go ×1CHASM · introduced test · go.temporal.io/server/chasm/lib/callback/TestRouteSystemCallbackRequest_Success/CHASMCHASMHSM · introduced test · go.temporal.io/server/chasm/lib/callback/TestRouteSystemCallbackRequest_Success/HSMHSMTestOnceMap · introduced test · go.temporal.io/server/common/collection/TestOnceMapTestOnceMapTestRouteSystemCallbackRequest_Success · introduced test · go.temporal.io/server/components/callbacks/TestRouteSystemCallbackRequest_SuccessTestRouteSystemCallbackR…TestOutboundQueueFactory_ChasmTaskGroupWiring · introduced test · go.temporal.io/server/service/history/TestOutboundQueueFactory_ChasmTaskGroupWiringTestOutboundQueueFactory…Archival_disabled · introduced test · go.temporal.io/server/service/history/TestQueueModule_ArchivalQueue/Archival_disabledArchival_disabledArchival_enabled · introduced test · go.temporal.io/server/service/history/TestQueueModule_ArchivalQueue/Archival_enabledArchival_enabledTestNewServer · introduced test · go.temporal.io/server/temporal/TestNewServerTestNewServerTestNewServerWithJSONEncoding · introduced test · go.temporal.io/server/temporal/TestNewServerWithJSONEncodingTestNewServerWithJSONEnc…with_OTEL_Collector_running · introduced test · go.temporal.io/server/temporal/TestNewServerWithOTEL/with_OTEL_Collector_runningwith_OTEL_Collector_runn…without_OTEL_Collector_running · introduced test · go.temporal.io/server/temporal/TestNewServerWithOTEL/without_OTEL_Collector_runningwithout_OTEL_Collector_r…ExampleNewServer · introduced test · go.temporal.io/server/temporaltest/ExampleNewServerExampleNewServerTestBaseServerOptions · introduced test · go.temporal.io/server/temporaltest/TestBaseServerOptionsTestBaseServerOptionsTestClientWithCustomInterceptor · introduced test · go.temporal.io/server/temporaltest/TestClientWithCustomInterceptorTestClientWithCustomInte…TestDefaultWorkerOptions · introduced test · go.temporal.io/server/temporaltest/TestDefaultWorkerOptionsTestDefaultWorkerOptionsTestNewServer · introduced test · go.temporal.io/server/temporaltest/TestNewServerTestNewServerTestNewWorkerWithOptions · introduced test · go.temporal.io/server/temporaltest/TestNewWorkerWithOptionsTestNewWorkerWithOptionsTestSearchAttributeRegistration · introduced test · go.temporal.io/server/temporaltest/TestSearchAttributeRegistrationTestSearchAttributeRegis…TestWorkerServiceHealthCheck · introduced test · go.temporal.io/server/tests/testcore/TestFunctionalTestBaseSuite/TestWorkerServiceHealthCheckTestWorkerServiceHealthC…Focused file · go.temporal.io/server/common/collection/oncemap.go · 84 LOCcollection/oncemap.go

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package collection
2
3 import "sync"
4
5 // OnceMap is a concurrent map which lazily constructs its values. Map values are initialized on-the-fly, using a
6 // provided construction function only when a key is accessed for the first time.
7 type OnceMap[K comparable, T any] struct {
8 mu sync.RWMutex
9 inner map[K]T
10 construct func(K) T
11 }
12
13 // NewOnceMap creates a [OnceMap] from a given construct function.
14 // construct should be kept light as it is called while holding a lock on the entire map.
15 > func NewOnceMap[K comparable, T any](construct func(K) T) *OnceMap[K, T] { oncemap.go ×1
16 > return &OnceMap[K, T]{
17 > construct: construct,
18 > inner: make(map[K]T, 0),
19 > }
20 > }
21
22 > func (m *OnceMap[K, T]) Get(key K) T { oncemap.go ×2
23 > m.mu.RLock()
24 > value, ok := m.inner[key]
25 > m.mu.RUnlock()
26 > if !ok {
27 > m.mu.Lock()
28 > defer m.mu.Unlock()
29 > if value, ok = m.inner[key]; !ok {
30 > value = m.construct(key)
31 > m.inner[key] = value
32 > }
33 }
34
35 > return value oncemap.go ×2
36 }
37
38 // FallibleOnceMap is a concurrent map which lazily constructs its values. Map values are initialized on-the-fly, using
39 // a provided construction function only when a key is accessed for the first time.
40 // If the construct function returns an error, the value is not cached.
41 type FallibleOnceMap[K comparable, T any] struct {
42 mu sync.RWMutex
43 inner map[K]T
44 construct func(K) (T, error)
45 }
46
47 // NewFallibleOnceMap creates a [FallibleOnceMap] from a given construct function.
48 // construct should be kept light as it is called while holding a lock on the entire map.
49 > func NewFallibleOnceMap[K comparable, T any](construct func(K) (T, error)) *FallibleOnceMap[K, T] { frontend_http_client.go ×1
50 > return &FallibleOnceMap[K, T]{
51 > construct: construct,
52 > inner: make(map[K]T, 0),
53 > }
54 > }
55
56 func (p *FallibleOnceMap[K, T]) Get(key K) (T, error) {
57 p.mu.RLock()
58 value, ok := p.inner[key]
59 p.mu.RUnlock()
60 if !ok {
61 p.mu.Lock()
62 defer p.mu.Unlock()
63 if value, ok = p.inner[key]; !ok {
64 var err error
65 value, err = p.construct(key)
66 if err != nil {
67 return value, err
68 }
69 p.inner[key] = value
70 }
71 }
72
73 return value, nil
74 }
75
76 func (p *FallibleOnceMap[K, T]) Pop(key K) (T, bool) {
77 p.mu.Lock()
78 defer p.mu.Unlock()
79 val, ok := p.inner[key]
80 if ok {
81 delete(p.inner, key)
82 }
83 return val, ok
84 }