Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3172ccfe
Unverified
Commit
3172ccfe
authored
Apr 18, 2023
by
Michael de Hoog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify
parent
3d632f70
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
26 deletions
+23
-26
queue.go
op-service/txmgr/queue.go
+23
-26
No files found.
op-service/txmgr/queue.go
View file @
3172ccfe
...
@@ -69,13 +69,11 @@ func (q *Queue[T]) Wait() {
...
@@ -69,13 +69,11 @@ func (q *Queue[T]) Wait() {
func
(
q
*
Queue
[
T
])
Send
(
ctx
context
.
Context
,
factory
TxFactory
[
T
],
receiptCh
chan
TxReceipt
[
T
])
error
{
func
(
q
*
Queue
[
T
])
Send
(
ctx
context
.
Context
,
factory
TxFactory
[
T
],
receiptCh
chan
TxReceipt
[
T
])
error
{
ctx
,
cancel
:=
mergeContexts
(
ctx
,
q
.
ctx
)
ctx
,
cancel
:=
mergeContexts
(
ctx
,
q
.
ctx
)
defer
cancel
()
defer
cancel
()
errChan
:=
make
(
chan
error
)
factoryErrCh
:=
make
(
chan
error
)
q
.
group
.
Go
(
func
()
error
{
q
.
group
.
Go
(
func
()
error
{
sender
,
err
:=
q
.
createTxSender
(
ctx
,
factory
,
receiptCh
)
return
q
.
sendTx
(
ctx
,
factory
,
factoryErrCh
,
receiptCh
)
errChan
<-
err
return
sender
()
})
})
return
<-
errChan
return
<-
factoryErrCh
}
}
// TrySend sends the next tx, but only if the number of pending txs is below the
// TrySend sends the next tx, but only if the number of pending txs is below the
...
@@ -91,42 +89,41 @@ func (q *Queue[T]) Send(ctx context.Context, factory TxFactory[T], receiptCh cha
...
@@ -91,42 +89,41 @@ func (q *Queue[T]) Send(ctx context.Context, factory TxFactory[T], receiptCh cha
func
(
q
*
Queue
[
T
])
TrySend
(
ctx
context
.
Context
,
factory
TxFactory
[
T
],
receiptCh
chan
TxReceipt
[
T
])
(
bool
,
error
)
{
func
(
q
*
Queue
[
T
])
TrySend
(
ctx
context
.
Context
,
factory
TxFactory
[
T
],
receiptCh
chan
TxReceipt
[
T
])
(
bool
,
error
)
{
ctx
,
cancel
:=
mergeContexts
(
ctx
,
q
.
ctx
)
ctx
,
cancel
:=
mergeContexts
(
ctx
,
q
.
ctx
)
defer
cancel
()
defer
cancel
()
errChan
:=
make
(
chan
error
)
factoryErrCh
:=
make
(
chan
error
)
queued
:=
q
.
group
.
TryGo
(
func
()
error
{
started
:=
q
.
group
.
TryGo
(
func
()
error
{
sender
,
err
:=
q
.
createTxSender
(
ctx
,
factory
,
receiptCh
)
return
q
.
sendTx
(
ctx
,
factory
,
factoryErrCh
,
receiptCh
)
errChan
<-
err
return
sender
()
})
})
if
!
queu
ed
{
if
!
start
ed
{
return
false
,
nil
return
false
,
nil
}
}
err
:=
<-
errChan
err
:=
<-
factoryErrCh
return
err
!=
nil
,
err
return
err
!=
nil
,
err
}
}
func
(
q
*
Queue
[
T
])
createTxSender
(
ctx
context
.
Context
,
factory
TxFactory
[
T
],
receiptCh
chan
TxReceipt
[
T
])
(
func
()
error
,
error
)
{
func
(
q
*
Queue
[
T
])
sendTx
(
ctx
context
.
Context
,
factory
TxFactory
[
T
],
factoryErrorCh
chan
error
,
receiptCh
chan
TxReceipt
[
T
])
error
{
// lock to prevent concurrent access to the tx factory
// lock to prevent concurrent access to the tx factory
q
.
lock
.
Lock
()
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
defer
q
.
lock
.
Unlock
()
candidate
,
id
,
err
:=
factory
(
ctx
)
candidate
,
id
,
err
:=
factory
(
ctx
)
factoryErrorCh
<-
err
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
// Factory returned an error which was returned in the channel. This means
// there was no tx to send, so return nil.
return
nil
}
}
q
.
pendingChanged
(
q
.
pending
.
Add
(
1
))
q
.
pendingChanged
(
q
.
pending
.
Add
(
1
))
return
func
()
error
{
defer
func
()
{
defer
func
()
{
q
.
pendingChanged
(
q
.
pending
.
Add
(
^
uint64
(
0
)))
// -1
q
.
pendingChanged
(
q
.
pending
.
Add
(
^
uint64
(
0
)))
// -1
}()
}()
receipt
,
err
:=
q
.
txMgr
.
Send
(
ctx
,
candidate
)
receipt
,
err
:=
q
.
txMgr
.
Send
(
ctx
,
candidate
)
receiptCh
<-
TxReceipt
[
T
]{
receiptCh
<-
TxReceipt
[
T
]{
ID
:
id
,
ID
:
id
,
Receipt
:
receipt
,
Receipt
:
receipt
,
Err
:
err
,
Err
:
err
,
}
}
return
err
return
err
},
nil
}
}
// mergeContexts creates a new Context that is canceled if either of the two
// mergeContexts creates a new Context that is canceled if either of the two
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment