good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
J
jrpc
Manage
Activity
Members
Labels
Plan
Issues
6
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
4
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
jrpc
Commits
d5afc247
Verified
Commit
d5afc247
authored
1 year ago
by
a
Browse files
Options
Downloads
Patches
Plain Diff
pooling
parent
4a3cb469
No related branches found
No related tags found
No related merge requests found
Pipeline
#29745
failed with stage
in 15 minutes and 20 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
contrib/client/pooling.go
+35
-3
35 additions, 3 deletions
contrib/client/pooling.go
with
35 additions
and
3 deletions
contrib/client/pooling.go
+
35
−
3
View file @
d5afc247
...
@@ -7,27 +7,59 @@ import (
...
@@ -7,27 +7,59 @@ import (
"sync/atomic"
"sync/atomic"
"gfx.cafe/open/jrpc"
"gfx.cafe/open/jrpc"
"gfx.cafe/open/jrpc/contrib/extension/subscription"
"gfx.cafe/open/jrpc/pkg/codec"
"gfx.cafe/open/jrpc/pkg/codec"
)
)
var
_
codec
.
Conn
=
(
*
Pooling
)(
nil
)
var
_
codec
.
Conn
=
(
*
Pooling
)(
nil
)
var
_
subscription
.
Conn
=
(
*
Pooling
)(
nil
)
type
Pooling
struct
{
type
Pooling
struct
{
dialer
func
(
ctx
context
.
Context
)
(
jrpc
.
Conn
,
error
)
dialer
func
(
ctx
context
.
Context
)
(
jrpc
.
Conn
,
error
)
conns
chan
codec
.
Conn
conns
chan
codec
.
Conn
base
codec
.
Conn
base
subscription
.
Conn
closed
atomic
.
Bool
closed
atomic
.
Bool
middleware
[]
codec
.
Middleware
middleware
[]
codec
.
Middleware
mu
sync
.
Mutex
mu
sync
.
Mutex
}
}
func
NewPooling
(
dialer
func
(
ctx
context
.
Context
)
(
jrpc
.
Conn
,
error
),
max
int
)
*
Pooling
{
func
(
p
*
Pooling
)
getBase
(
ctx
context
.
Context
)
(
subscription
.
Conn
,
error
)
{
p
.
mu
.
Lock
()
defer
p
.
mu
.
Unlock
()
if
p
.
base
==
nil
{
conn
,
err
:=
subscription
.
UpgradeConn
(
p
.
dialer
(
ctx
))
if
err
!=
nil
{
return
nil
,
err
}
p
.
base
=
conn
}
return
p
.
base
,
nil
}
func
(
p
*
Pooling
)
Notify
(
ctx
context
.
Context
,
method
string
,
params
any
)
error
{
base
,
err
:=
p
.
getBase
(
ctx
)
if
err
!=
nil
{
return
err
}
return
base
.
Notify
(
ctx
,
method
,
params
)
}
func
(
p
*
Pooling
)
Subscribe
(
ctx
context
.
Context
,
namespace
string
,
channel
any
,
args
any
)
(
subscription
.
ClientSubscription
,
error
)
{
base
,
err
:=
p
.
getBase
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
return
base
.
Subscribe
(
ctx
,
namespace
,
channel
,
args
)
}
func
NewPooling
(
ctx
context
.
Context
,
dialer
func
(
ctx
context
.
Context
)
(
jrpc
.
Conn
,
error
),
max
int
)
(
*
Pooling
,
error
)
{
r
:=
&
Pooling
{
r
:=
&
Pooling
{
dialer
:
dialer
,
dialer
:
dialer
,
conns
:
make
(
chan
codec
.
Conn
,
max
),
conns
:
make
(
chan
codec
.
Conn
,
max
),
}
}
return
r
return
r
,
nil
}
}
func
(
r
*
Pooling
)
Do
(
ctx
context
.
Context
,
result
any
,
method
string
,
params
any
)
error
{
func
(
r
*
Pooling
)
Do
(
ctx
context
.
Context
,
result
any
,
method
string
,
params
any
)
error
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment