Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
Account 是一个线程不安全的结构体,实现了Accountable接口
func (*Account) GetBalance ¶
func (*Account) SetBalance ¶
func (*Account) Transfer ¶
func (a *Account) Transfer(to Accountable, amount int64)
type AccountV1 ¶
type AccountV1 struct { Account // contains filtered or unexported fields }
AccountV1 组合了Account,通过锁,保证线程安全
func (*AccountV1) Transfer ¶
func (a *AccountV1) Transfer(to Accountable, amount int64)
type AccountV2 ¶
type AccountV2 struct {
Account
}
AccountV2 组合了Account,通过借助外部的Allocator,保证线程安全
func (*AccountV2) Transfer ¶
func (a *AccountV2) Transfer(to Accountable, amount int64)
type AccountV3 ¶
type AccountV3 struct { Account // contains filtered or unexported fields }
AccountV3 组合了Account,通过信号量,保证线程安全
func NewAccountV3 ¶
func (*AccountV3) Transfer ¶
func (a *AccountV3) Transfer(to Accountable, amount int64)
type Accountable ¶
type Accountable interface { GetId() int64 GetBalance() int64 SetBalance(amount int64) Transfer(to Accountable, amount int64) }
type Bank ¶
type Bank struct {
// contains filtered or unexported fields
}
func (*Bank) Transfer ¶
func (bank *Bank) Transfer(from Accountable, to Accountable, amount int64)
Transfer 通过银行级别的锁,保证线程安全,不必考虑Accountable对象本身是否线程安全
func (*Bank) TransferAsync ¶
func (bank *Bank) TransferAsync(from Accountable, to Accountable, amount int64)
TransferAsync 通过银行级别的channel,把转账业务由并行转串行,保证线程安全,不必考虑Accountable对象本身是否线程安全
type TransferTask ¶
type TransferTask struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.