@@ -94,16 +94,14 @@ object RabbitClient {
94
94
threadFactory : Option [F [ThreadFactory ]],
95
95
executionContext : Option [F [ExecutionContext ]]
96
96
) {
97
- def withSslContext (sslContext : SSLContext ): Builder [F ] = new Builder [F ](
98
- config = config,
99
- sslContext = Some (sslContext),
100
- saslConfig = saslConfig,
101
- metricsCollector = metricsCollector,
102
- threadFactory = threadFactory,
103
- executionContext = executionContext
104
- ) {}
105
-
106
- def withSaslConfig (saslConfig : SaslConfig ): Builder [F ] = new Builder [F ](
97
+ private def copy (
98
+ config : Fs2RabbitConfig = config,
99
+ sslContext : Option [SSLContext ] = sslContext,
100
+ saslConfig : SaslConfig = saslConfig,
101
+ metricsCollector : Option [MetricsCollector ] = metricsCollector,
102
+ threadFactory : Option [F [ThreadFactory ]] = threadFactory,
103
+ executionContext : Option [F [ExecutionContext ]] = executionContext
104
+ ): Builder [F ] = new Builder [F ](
107
105
config = config,
108
106
sslContext = sslContext,
109
107
saslConfig = saslConfig,
@@ -112,38 +110,22 @@ object RabbitClient {
112
110
executionContext = executionContext
113
111
) {}
114
112
115
- def withMetricsCollector (metricsCollector : MetricsCollector ): Builder [F ] = new Builder [F ](
116
- config = config,
117
- sslContext = sslContext,
118
- saslConfig = saslConfig,
119
- metricsCollector = Some (metricsCollector),
120
- threadFactory = threadFactory,
121
- executionContext = executionContext
122
- ) {}
113
+ def withSslContext (sslContext : SSLContext ): Builder [F ] = copy(sslContext = Some (sslContext))
123
114
124
- def withThreadFactory (threadFactory : F [ThreadFactory ]): Builder [F ] = new Builder [F ](
125
- config = config,
126
- sslContext = sslContext,
127
- saslConfig = saslConfig,
128
- metricsCollector = metricsCollector,
129
- threadFactory = Some (threadFactory),
130
- executionContext = executionContext
131
- ) {}
115
+ def withSaslConfig (saslConfig : SaslConfig ): Builder [F ] = copy(saslConfig = saslConfig)
116
+
117
+ def withMetricsCollector (metricsCollector : MetricsCollector ): Builder [F ] =
118
+ copy(metricsCollector = Some (metricsCollector))
119
+
120
+ def withThreadFactory (threadFactory : F [ThreadFactory ]): Builder [F ] = copy(threadFactory = Some (threadFactory))
132
121
133
122
def withExecutionContext (executionContext : F [ExecutionContext ]): Builder [F ] =
134
- new Builder [F ](
135
- config = config,
136
- sslContext = sslContext,
137
- saslConfig = saslConfig,
138
- metricsCollector = metricsCollector,
139
- threadFactory = threadFactory,
140
- executionContext = Some (executionContext)
141
- ) {}
123
+ copy(executionContext = Some (executionContext))
142
124
143
125
def build (dispatcher : Dispatcher [F ]): F [RabbitClient [F ]] =
144
126
create[F ](config, dispatcher, sslContext, saslConfig, metricsCollector, threadFactory, executionContext)
145
127
146
- def resource () : Resource [F , RabbitClient [F ]] =
128
+ def resource : Resource [F , RabbitClient [F ]] =
147
129
Dispatcher [F ].evalMap(build)
148
130
}
149
131
0 commit comments