Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
dc78282e
Commit
dc78282e
authored
Jul 24, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e42b1b7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
go/transaction/transaction.go
go/transaction/transaction.go
+80
-0
No files found.
go/transaction/transaction.go
View file @
dc78282e
...
...
@@ -13,4 +13,84 @@
package
transaction
import
(
"context"
"sync"
)
// transaction implements Transaction.
type
transaction
struct
{
mu
sync
.
Mutex
status
Status
datav
[]
DataManager
syncv
[]
Synchronizer
// metadata
user
string
description
string
extension
string
// XXX
}
// ctxKey is type private to transaction package, used as key in contexts.
type
ctxKey
struct
{}
// getTxn returns transaction associated with provided context.
// nil is returned is there is no association.
func
getTxn
(
ctx
context
.
Context
)
*
transaction
{
t
:=
ctx
.
Value
(
ctxKey
{})
if
t
==
nil
{
return
nil
}
return
t
.
(
*
transaction
)
}
// currentTxn serves Current.
func
currentTxn
(
ctx
context
.
Context
)
Transaction
{
txn
:=
getTxn
(
ctx
)
if
txn
==
nil
{
panic
(
"transaction: no current transaction"
)
}
return
txn
}
// newTxn serves New.
func
newTxn
(
ctx
context
.
Context
)
(
Transaction
,
context
.
Context
)
{
if
getTxn
(
ctx
)
!=
nil
{
panic
(
"transaction: nested transactions are not supported"
)
}
txn
:=
&
transaction
{
status
:
Active
}
txnCtx
:=
context
.
WithValue
(
ctx
,
ctxKey
{},
txn
)
return
txn
,
txnCtx
}
func
(
txn
*
transaction
)
Status
()
Status
{
txn
.
mu
.
Lock
()
defer
txn
.
mu
.
Unlock
()
return
txn
.
status
}
func
(
txn
*
transaction
)
Commit
(
ctx
context
.
Context
)
error
{
panic
(
"TODO"
)
}
func
(
txn
*
transaction
)
Abort
()
{
panic
(
"TODO"
)
}
func
(
txn
*
transaction
)
Join
(
dm
DataManager
)
{
panic
(
"TODO"
)
}
func
(
txn
*
transaction
)
RegisterSync
(
sync
Synchronizer
)
{
panic
(
"TODO"
)
}
// ---- meta ----
func
(
txn
*
transaction
)
User
()
string
{
return
txn
.
user
}
func
(
txn
*
transaction
)
Description
()
string
{
return
txn
.
description
}
func
(
txn
*
transaction
)
Extension
()
string
{
return
txn
.
extension
}
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