88
99public struct Future < A> {
1010 let threadID : MVar < Optional < ThreadID > >
11- let cOptional : IVar < Optional < A > >
11+ let completionLock : IVar < Optional < A > >
1212 let finalizers : MVar < [ Optional < A > -> ( ) ] >
1313
1414 private init ( _ threadID : MVar < Optional < ThreadID > > , _ cOptional : IVar < Optional < A > > , _ finalizers : MVar < [ Optional < A > -> ( ) ] > ) {
1515 self . threadID = threadID
16- self . cOptional = cOptional
16+ self . completionLock = cOptional
1717 self . finalizers = finalizers
1818 }
1919
2020 public func read( ) -> Optional < A > {
21- return self . cOptional . read ( )
21+ return self . completionLock . read ( )
2222 }
2323
2424 public func then( finalize : Optional < A > -> ( ) ) -> Future < A > {
2525 do {
2626 let ma : Optional < Optional < A > > = try self . finalizers. modify { sTodo in
27- let res = self . cOptional . tryRead ( )
27+ let res = self . completionLock . tryRead ( )
2828 if res == nil {
2929 return ( sTodo + [ finalize] , res)
3030 }
@@ -44,7 +44,7 @@ public struct Future<A> {
4444 }
4545
4646 private func complete( r : Optional < A > ) -> Optional < A > {
47- return self . cOptional . tryPut ( r) ? r : self . cOptional . read ( )
47+ return self . completionLock . tryPut ( r) ? r : self . completionLock . read ( )
4848 }
4949
5050 private func runFinalizerWithOptional< A> ( val : Optional < A > ) -> ( Optional < A > -> ( ) ) -> ThreadID {
@@ -60,10 +60,10 @@ public func forkFutures<A>(ios : [() -> A]) -> Chan<Optional<A>> {
6060
6161public func forkFuture< A> ( io : ( ) throws -> A ) -> Future < A > {
6262 let msTid = MVar < ThreadID ? > ( )
63- let Optional : IVar < A ? > = IVar ( )
63+ let lock : IVar < A ? > = IVar ( )
6464 let msTodo : MVar < [ A ? -> ( ) ] > = MVar ( initial: [ ] )
6565
66- let p = Future ( msTid, Optional , msTodo)
66+ let p = Future ( msTid, lock , msTodo)
6767 let act : ( ) -> ( ) = {
6868 p. threadID. put ( . Some( myTheadID ( ) ) )
6969 _ = p. complete ( {
@@ -80,7 +80,9 @@ public func forkFuture<A>(io : () throws -> A) -> Future<A> {
8080 p. threadID. modify_ ( { _ in . None } )
8181 let val = p. complete ( paranoid)
8282 let sTodo = p. finalizers. swap ( [ ] )
83- sTodo. forEach { _ in p. runFinalizerWithOptional ( val) }
83+ sTodo. forEach { _ in
84+ let _ = p. runFinalizerWithOptional ( val)
85+ }
8486 }
8587
8688 _ = forkIO {
0 commit comments