ccstm icon indicating copy to clipboard operation
ccstm copied to clipboard

TxnLocal enhancements

Open nbronson opened this issue 14 years ago • 1 comments

TxnLocal should get some of the methods from Ref:

  • the access shortcuts apply() and update(v)
  • read+write forms swap, transform, transformIfDefined, +=, -=, and *=

I think compareAndSet (and other Ref methods whose success or failure is determined by concurrent accesses) would be misleading, because TxnLocal instances are isolated.

Also, overriding initialValue should perhaps be replaced with a by-name parameter to a factory method. This is more Scala-ish, but makes it more difficult to get access to the current Txn context.

nbronson avatar Jun 28 '10 18:06 nbronson

The factory method with by-name initial value doesn't mean you cannot keep the possibility to override initialValue and thereby gain access to the Txn...

// { object TxnLocal { def apply[ T ](init: => T) = new TxnLocal { override protected def initialValue( txn: Txn ) = init } }

val test = TxnLocal( false ) // }

Sciss avatar Nov 13 '10 23:11 Sciss