Commit dc78282e authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e42b1b7f
......@@ -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 }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment