diff --git a/README.md b/README.md index 3158acd..95a0f18 100644 --- a/README.md +++ b/README.md @@ -227,29 +227,6 @@ let left = divideLeftMultiplyRight.apply(Either.left(4)) // 2 let right = divideLeftMultiplyRight.apply(Either.right(7)) // 14 ``` -**Concurrency** - -```swift -import class Swiftz.Chan - -//: A Channel is an unbounded FIFO stream of values with special semantics -//: for reads and writes. -let chan : Chan = Chan() - -//: All writes to the Channel always succeed. The Channel now contains `1`. -chan.write(1) // happens immediately - -//: Reads to non-empty Channels occur immediately. The Channel is now empty. -let x1 = chan.read() - -//: But if we read from an empty Channel the read blocks until we write to the Channel again. -dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * Double(NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { - chan.write(2) // Causes the read to suceed and unblocks the reading thread. -}) - -let x2 = chan.read() // Blocks until the dispatch block is executed and the Channel becomes non-empty. -``` - Operators --------- diff --git a/Swiftz-iOS.xcodeproj/project.pbxproj b/Swiftz-iOS.xcodeproj/project.pbxproj index b3c0812..a7db254 100644 --- a/Swiftz-iOS.xcodeproj/project.pbxproj +++ b/Swiftz-iOS.xcodeproj/project.pbxproj @@ -67,17 +67,13 @@ 84A88F2D1A70C77B003D53CF /* Tuple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88DE11A70C2B5003D53CF /* Tuple.swift */; }; 84A88F2E1A70C77B003D53CF /* TupleExt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88DE21A70C2B5003D53CF /* TupleExt.swift */; }; 84A88F671A70C7A0003D53CF /* ArrayExtSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ECC1A70C707003D53CF /* ArrayExtSpec.swift */; }; - 84A88F681A70C7A0003D53CF /* ChanSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ECD1A70C707003D53CF /* ChanSpec.swift */; }; - 84A88F691A70C7A0003D53CF /* ConcurrentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ECE1A70C707003D53CF /* ConcurrentTests.swift */; }; 84A88F6A1A70C7A0003D53CF /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ECF1A70C707003D53CF /* EitherSpec.swift */; }; 84A88F6B1A70C7A0003D53CF /* FunctorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED01A70C707003D53CF /* FunctorSpec.swift */; }; - 84A88F6C1A70C7A0003D53CF /* FutureSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED11A70C707003D53CF /* FutureSpec.swift */; }; 84A88F6D1A70C7A0003D53CF /* HListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED21A70C707003D53CF /* HListSpec.swift */; }; 84A88F6E1A70C7A0003D53CF /* JSONSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED31A70C707003D53CF /* JSONSpec.swift */; }; 84A88F6F1A70C7A0003D53CF /* ListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED41A70C707003D53CF /* ListSpec.swift */; }; 84A88F701A70C7A0003D53CF /* MaybeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED51A70C707003D53CF /* MaybeSpec.swift */; }; 84A88F711A70C7A0003D53CF /* MonoidSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED61A70C707003D53CF /* MonoidSpec.swift */; }; - 84A88F721A70C7A0003D53CF /* MVarSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED71A70C707003D53CF /* MVarSpec.swift */; }; 84A88F731A70C7A0003D53CF /* OptionalExtSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED81A70C707003D53CF /* OptionalExtSpec.swift */; }; 84A88F741A70C7A0003D53CF /* PartyExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88ED91A70C707003D53CF /* PartyExample.swift */; }; 84A88F751A70C7A0003D53CF /* ResultSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88EDA1A70C707003D53CF /* ResultSpec.swift */; }; @@ -198,17 +194,13 @@ 84A88E951A70C649003D53CF /* Optional.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Optional.swift; path = ../Carthage/Checkouts/Swiftx/Swiftx/Optional.swift; sourceTree = ""; }; 84A88E961A70C649003D53CF /* Result.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Result.swift; path = ../Carthage/Checkouts/Swiftx/Swiftx/Result.swift; sourceTree = ""; }; 84A88ECC1A70C707003D53CF /* ArrayExtSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArrayExtSpec.swift; path = SwiftzTests/ArrayExtSpec.swift; sourceTree = SOURCE_ROOT; }; - 84A88ECD1A70C707003D53CF /* ChanSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChanSpec.swift; path = SwiftzTests/ChanSpec.swift; sourceTree = SOURCE_ROOT; }; - 84A88ECE1A70C707003D53CF /* ConcurrentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ConcurrentTests.swift; path = SwiftzTests/ConcurrentTests.swift; sourceTree = SOURCE_ROOT; }; 84A88ECF1A70C707003D53CF /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = EitherSpec.swift; path = SwiftzTests/EitherSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED01A70C707003D53CF /* FunctorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FunctorSpec.swift; path = SwiftzTests/FunctorSpec.swift; sourceTree = SOURCE_ROOT; }; - 84A88ED11A70C707003D53CF /* FutureSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FutureSpec.swift; path = SwiftzTests/FutureSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED21A70C707003D53CF /* HListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HListSpec.swift; path = SwiftzTests/HListSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED31A70C707003D53CF /* JSONSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSONSpec.swift; path = SwiftzTests/JSONSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED41A70C707003D53CF /* ListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ListSpec.swift; path = SwiftzTests/ListSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED51A70C707003D53CF /* MaybeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MaybeSpec.swift; path = SwiftzTests/MaybeSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED61A70C707003D53CF /* MonoidSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MonoidSpec.swift; path = SwiftzTests/MonoidSpec.swift; sourceTree = SOURCE_ROOT; }; - 84A88ED71A70C707003D53CF /* MVarSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MVarSpec.swift; path = SwiftzTests/MVarSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED81A70C707003D53CF /* OptionalExtSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = OptionalExtSpec.swift; path = SwiftzTests/OptionalExtSpec.swift; sourceTree = SOURCE_ROOT; }; 84A88ED91A70C707003D53CF /* PartyExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PartyExample.swift; path = SwiftzTests/PartyExample.swift; sourceTree = SOURCE_ROOT; }; 84A88EDA1A70C707003D53CF /* ResultSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ResultSpec.swift; path = SwiftzTests/ResultSpec.swift; sourceTree = SOURCE_ROOT; }; @@ -273,7 +265,6 @@ isa = PBXGroup; children = ( 84A88F871A70C953003D53CF /* Examples */, - 84A88F881A70C967003D53CF /* Concurrent */, 84A88F8A1A70C982003D53CF /* Data */, 84A88F891A70C97C003D53CF /* Ext */, 84A88D611A70C23D003D53CF /* Supporting Files */, @@ -412,17 +403,6 @@ name = Examples; sourceTree = ""; }; - 84A88F881A70C967003D53CF /* Concurrent */ = { - isa = PBXGroup; - children = ( - 84A88ECD1A70C707003D53CF /* ChanSpec.swift */, - 84A88ECE1A70C707003D53CF /* ConcurrentTests.swift */, - 84A88ED11A70C707003D53CF /* FutureSpec.swift */, - 84A88ED71A70C707003D53CF /* MVarSpec.swift */, - ); - name = Concurrent; - sourceTree = ""; - }; 84A88F891A70C97C003D53CF /* Ext */ = { isa = PBXGroup; children = ( @@ -584,18 +564,14 @@ buildActionMask = 2147483647; files = ( 84A88F671A70C7A0003D53CF /* ArrayExtSpec.swift in Sources */, - 84A88F681A70C7A0003D53CF /* ChanSpec.swift in Sources */, - 84A88F691A70C7A0003D53CF /* ConcurrentTests.swift in Sources */, 84A88F6A1A70C7A0003D53CF /* EitherSpec.swift in Sources */, 84A88F6B1A70C7A0003D53CF /* FunctorSpec.swift in Sources */, - 84A88F6C1A70C7A0003D53CF /* FutureSpec.swift in Sources */, 84BB57671AA12E4300214BC5 /* StateSpec.swift in Sources */, 84A88F6D1A70C7A0003D53CF /* HListSpec.swift in Sources */, 84A88F6E1A70C7A0003D53CF /* JSONSpec.swift in Sources */, 84A88F6F1A70C7A0003D53CF /* ListSpec.swift in Sources */, 84A88F701A70C7A0003D53CF /* MaybeSpec.swift in Sources */, 84A88F711A70C7A0003D53CF /* MonoidSpec.swift in Sources */, - 84A88F721A70C7A0003D53CF /* MVarSpec.swift in Sources */, 84A88F731A70C7A0003D53CF /* OptionalExtSpec.swift in Sources */, 84A88F741A70C7A0003D53CF /* PartyExample.swift in Sources */, 84A88F751A70C7A0003D53CF /* ResultSpec.swift in Sources */, diff --git a/Swiftz.xcodeproj/project.pbxproj b/Swiftz.xcodeproj/project.pbxproj index 9a5fb7b..7f83ace 100644 --- a/Swiftz.xcodeproj/project.pbxproj +++ b/Swiftz.xcodeproj/project.pbxproj @@ -14,17 +14,13 @@ 84A88F9E1A71DF7F003D53CF /* Swiftz.h in Headers */ = {isa = PBXBuildFile; fileRef = 84A88F9D1A71DF7F003D53CF /* Swiftz.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84A88FA41A71DF7F003D53CF /* Swiftz.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A88F981A71DF7F003D53CF /* Swiftz.framework */; }; 84A88FC91A71DFA0003D53CF /* ArrayExtSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FB41A71DFA0003D53CF /* ArrayExtSpec.swift */; }; - 84A88FCA1A71DFA0003D53CF /* ChanSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FB51A71DFA0003D53CF /* ChanSpec.swift */; }; - 84A88FCB1A71DFA0003D53CF /* ConcurrentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FB61A71DFA0003D53CF /* ConcurrentTests.swift */; }; 84A88FCC1A71DFA0003D53CF /* EitherSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FB71A71DFA0003D53CF /* EitherSpec.swift */; }; 84A88FCD1A71DFA0003D53CF /* FunctorSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FB81A71DFA0003D53CF /* FunctorSpec.swift */; }; - 84A88FCE1A71DFA0003D53CF /* FutureSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FB91A71DFA0003D53CF /* FutureSpec.swift */; }; 84A88FCF1A71DFA0003D53CF /* HListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FBA1A71DFA0003D53CF /* HListSpec.swift */; }; 84A88FD01A71DFA0003D53CF /* JSONSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FBB1A71DFA0003D53CF /* JSONSpec.swift */; }; 84A88FD11A71DFA0003D53CF /* ListSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FBC1A71DFA0003D53CF /* ListSpec.swift */; }; 84A88FD21A71DFA0003D53CF /* MaybeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FBD1A71DFA0003D53CF /* MaybeSpec.swift */; }; 84A88FD31A71DFA0003D53CF /* MonoidSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FBE1A71DFA0003D53CF /* MonoidSpec.swift */; }; - 84A88FD41A71DFA0003D53CF /* MVarSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FBF1A71DFA0003D53CF /* MVarSpec.swift */; }; 84A88FD51A71DFA0003D53CF /* OptionalExtSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FC01A71DFA0003D53CF /* OptionalExtSpec.swift */; }; 84A88FD61A71DFA0003D53CF /* PartyExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FC11A71DFA0003D53CF /* PartyExample.swift */; }; 84A88FD71A71DFA0003D53CF /* ResultSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84A88FC21A71DFA0003D53CF /* ResultSpec.swift */; }; @@ -145,17 +141,13 @@ 84A88FA31A71DF7F003D53CF /* SwiftzTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftzTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 84A88FA91A71DF7F003D53CF /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 84A88FB41A71DFA0003D53CF /* ArrayExtSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayExtSpec.swift; sourceTree = ""; usesTabs = 1; }; - 84A88FB51A71DFA0003D53CF /* ChanSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChanSpec.swift; sourceTree = ""; usesTabs = 1; }; - 84A88FB61A71DFA0003D53CF /* ConcurrentTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConcurrentTests.swift; sourceTree = ""; usesTabs = 1; }; 84A88FB71A71DFA0003D53CF /* EitherSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EitherSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FB81A71DFA0003D53CF /* FunctorSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FunctorSpec.swift; sourceTree = ""; usesTabs = 1; }; - 84A88FB91A71DFA0003D53CF /* FutureSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FutureSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FBA1A71DFA0003D53CF /* HListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HListSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FBB1A71DFA0003D53CF /* JSONSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FBC1A71DFA0003D53CF /* ListSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FBD1A71DFA0003D53CF /* MaybeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaybeSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FBE1A71DFA0003D53CF /* MonoidSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MonoidSpec.swift; sourceTree = ""; usesTabs = 1; }; - 84A88FBF1A71DFA0003D53CF /* MVarSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MVarSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FC01A71DFA0003D53CF /* OptionalExtSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OptionalExtSpec.swift; sourceTree = ""; usesTabs = 1; }; 84A88FC11A71DFA0003D53CF /* PartyExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PartyExample.swift; sourceTree = ""; usesTabs = 1; }; 84A88FC21A71DFA0003D53CF /* ResultSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResultSpec.swift; sourceTree = ""; usesTabs = 1; }; @@ -297,7 +289,6 @@ isa = PBXGroup; children = ( 84A890591A71E1D7003D53CF /* Examples */, - 84A890581A71E1C5003D53CF /* Concurrent */, 84A8905A1A71E1EE003D53CF /* Data */, 84A890571A71E1B5003D53CF /* Ext */, 84A88FA81A71DF7F003D53CF /* Supporting Files */, @@ -415,17 +406,6 @@ name = Ext; sourceTree = ""; }; - 84A890581A71E1C5003D53CF /* Concurrent */ = { - isa = PBXGroup; - children = ( - 84A88FB51A71DFA0003D53CF /* ChanSpec.swift */, - 84A88FB61A71DFA0003D53CF /* ConcurrentTests.swift */, - 84A88FB91A71DFA0003D53CF /* FutureSpec.swift */, - 84A88FBF1A71DFA0003D53CF /* MVarSpec.swift */, - ); - name = Concurrent; - sourceTree = ""; - }; 84A890591A71E1D7003D53CF /* Examples */ = { isa = PBXGroup; children = ( @@ -649,18 +629,15 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 84A88FCA1A71DFA0003D53CF /* ChanSpec.swift in Sources */, 84A88FD21A71DFA0003D53CF /* MaybeSpec.swift in Sources */, 84A88FD91A71DFA0003D53CF /* ShapeExample.swift in Sources */, 84A88FDC1A71DFA0003D53CF /* TupleExtSpec.swift in Sources */, - 84A88FCB1A71DFA0003D53CF /* ConcurrentTests.swift in Sources */, 84A88FD61A71DFA0003D53CF /* PartyExample.swift in Sources */, 84BB57641AA12D2200214BC5 /* StateSpec.swift in Sources */, 84A88FCF1A71DFA0003D53CF /* HListSpec.swift in Sources */, 84A88FDB1A71DFA0003D53CF /* ThoseSpec.swift in Sources */, 84A88FDD1A71DFA0003D53CF /* UserExample.swift in Sources */, 84A88FC91A71DFA0003D53CF /* ArrayExtSpec.swift in Sources */, - 84A88FCE1A71DFA0003D53CF /* FutureSpec.swift in Sources */, 84A88FD51A71DFA0003D53CF /* OptionalExtSpec.swift in Sources */, 84A88FCD1A71DFA0003D53CF /* FunctorSpec.swift in Sources */, 84A88FD11A71DFA0003D53CF /* ListSpec.swift in Sources */, @@ -668,7 +645,6 @@ 84A88FD71A71DFA0003D53CF /* ResultSpec.swift in Sources */, 84A88FD31A71DFA0003D53CF /* MonoidSpec.swift in Sources */, 84A88FDA1A71DFA0003D53CF /* StringExtSpec.swift in Sources */, - 84A88FD41A71DFA0003D53CF /* MVarSpec.swift in Sources */, 84A88FCC1A71DFA0003D53CF /* EitherSpec.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Swiftz/Chan.swift b/Swiftz/Chan.swift index 278a42f..fdb6cc1 100644 --- a/Swiftz/Chan.swift +++ b/Swiftz/Chan.swift @@ -18,6 +18,7 @@ public final class Chan { let cond : UnsafeMutablePointer let matt : UnsafeMutablePointer + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public init() { self.stream = [] var mattr : UnsafeMutablePointer = UnsafeMutablePointer.alloc(sizeof(pthread_mutexattr_t)) @@ -38,6 +39,7 @@ public final class Chan { } /// Writes a value to a channel. + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func write(a : A) { pthread_mutex_lock(mutex) stream.append(a) @@ -46,6 +48,7 @@ public final class Chan { } /// Reads a value from the channel. + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func read() -> A { pthread_mutex_lock(mutex) while (stream.isEmpty) { @@ -58,11 +61,13 @@ public final class Chan { } /// Write | Writes a value to a channel. +@availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func <-(chan : Chan, value : A) -> Void { chan.write(value) } /// Read | Reads a value from the channel. +@availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public prefix func <-(chan : Chan) -> A { return chan.read() } diff --git a/Swiftz/ExecutionContext.swift b/Swiftz/ExecutionContext.swift index 78c7cb5..c045764 100644 --- a/Swiftz/ExecutionContext.swift +++ b/Swiftz/ExecutionContext.swift @@ -15,5 +15,6 @@ public protocol ExecutionContext { /// Computes a value for a Future given a work block. /// /// When work concludes this function must execute Future.sig(_:) to fulfill the Future. + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") func submit(x: Future, work: () -> A) } diff --git a/Swiftz/Future.swift b/Swiftz/Future.swift index 933515a..7b30d26 100644 --- a/Swiftz/Future.swift +++ b/Swiftz/Future.swift @@ -21,8 +21,9 @@ public final class Future : K1 { // FIXME: Would like to add a uniqueid to the label let resultQueue = dispatch_queue_create("com.typelift.swift.future.resultQueue", DISPATCH_QUEUE_CONCURRENT) - let execCtx: ExecutionContext // for map - public init(exec: ExecutionContext) { + let execCtx : ExecutionContext // for map + + public init(exec : ExecutionContext) { dispatch_suspend(self.resultQueue) execCtx = exec } @@ -34,7 +35,8 @@ public final class Future : K1 { exec.submit(self, work: a) } - /// Forces a value to be computed + /// Forces a value to be computed + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func result() -> A { var result : A? = nil dispatch_sync(resultQueue, { @@ -43,7 +45,7 @@ public final class Future : K1 { return result! } - internal func sig(x: A) { + internal func sig(x : A) { assert(self.value == nil, "Future cannot complete more than once") self.value = x dispatch_resume(self.resultQueue) @@ -51,10 +53,12 @@ public final class Future : K1 { /// Returns a future that maps the results of the receiver through a function in the same /// execution context. + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func map(f: A -> B) -> Future { return Future(exec: execCtx, f(self.result())) } + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func flatMap(f: A -> Future) -> Future { return Future(exec: execCtx, f(self.result()).result()) } diff --git a/Swiftz/GCDExecutionContext.swift b/Swiftz/GCDExecutionContext.swift index 61ef4cf..3bc3dac 100644 --- a/Swiftz/GCDExecutionContext.swift +++ b/Swiftz/GCDExecutionContext.swift @@ -8,10 +8,14 @@ import Dispatch +@availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public let gcdExecutionContext = GCDExecutionContext() + +@availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public let gcdDispatchQueueGlobal = dispatch_queue_create("com.typelift.swiftz.globalExecutionContextQueue", DISPATCH_QUEUE_CONCURRENT) public struct GCDExecutionContext : ExecutionContext { + @availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public func submit(x: Future, work: () -> A) { dispatch_async(gcdDispatchQueueGlobal, { x.sig(work()) }) } diff --git a/Swiftz/MVar.swift b/Swiftz/MVar.swift index a9df573..d8e9490 100644 --- a/Swiftz/MVar.swift +++ b/Swiftz/MVar.swift @@ -16,6 +16,7 @@ import Darwin /// advertise an MVar and spark a computation that depends on a value computed in another thread. /// The first thread blocks waiting for the second to finish, then immediatly continues its work /// once a value has been put into the MVar. +@availability(*, deprecated=2.1, message="Concurrency primitives are being moved to Concurrent.framework") public final class MVar : K1 { var value : Optional<(() -> A)> diff --git a/SwiftzTests/ChanSpec.swift b/SwiftzTests/ChanSpec.swift deleted file mode 100644 index cf6e88f..0000000 --- a/SwiftzTests/ChanSpec.swift +++ /dev/null @@ -1,18 +0,0 @@ -// -// ChanSpec.swift -// swiftz -// -// Created by Robert Widmann on 1/19/15. -// Copyright (c) 2015 TypeLift. All rights reserved. -// - -import XCTest -import Swiftz - -class ChanSpec : XCTestCase { - func testConcurrentChan() { - var chan: Chan = Chan() - let ft = Future(exec: gcdExecutionContext, { usleep(1); chan.write(2); return 2 }()) - XCTAssert(chan.read() == ft.result(), "simple read chan") - } -} diff --git a/SwiftzTests/ConcurrentTests.swift b/SwiftzTests/ConcurrentTests.swift deleted file mode 100644 index d0ff430..0000000 --- a/SwiftzTests/ConcurrentTests.swift +++ /dev/null @@ -1,38 +0,0 @@ -// -// ConcurrentTests.swift -// swiftz -// -// Created by Maxwell Swadling on 9/06/2014. -// Copyright (c) 2014 Maxwell Swadling. All rights reserved. -// - -import XCTest -import Swiftz - -class ConcurrentTests: XCTestCase { - func testPerformanceExample() { - // concurrent pi - let term:(Chan, CDouble) -> Void = {(ch: Chan, k: CDouble) -> Void in - ch <- (4 * pow(-1, k) / (2 * k + 1)) - } - - let pi:Int -> CDouble = { - (n:Int) -> CDouble in - let ch = Chan() - for k in (0..(exec: gcdExecutionContext, { return term(ch, CDouble(k)) }()) - } - var f = 0.0 - for k in (0.. = Future(exec: gcdExecutionContext, { - usleep(1) - return 4 - }()) - XCTAssert(x.result() == x.result(), "future") - XCTAssert(x.map({ $0.description }).result() == "4", "future map") - XCTAssert(x.flatMap({ (x: Int) -> Future in - return Future(exec: gcdExecutionContext, { usleep(1); return x + 1 }()) - }).result() == 5, "future flatMap") - - // let x: Future = Future(exec: gcdExecutionContext, { - // return NSString.stringWithContentsOfURL(NSURL.URLWithString("http://github.com"), encoding: 0, error: nil) - // }) - // let x1 = (x.result().lengthOfBytesUsingEncoding(NSUTF8StringEncoding)) - // let x2 = (x.result().lengthOfBytesUsingEncoding(NSUTF8StringEncoding)) - // XCTAssert(x1 == x2) - } -} diff --git a/SwiftzTests/MVarSpec.swift b/SwiftzTests/MVarSpec.swift deleted file mode 100644 index 4085231..0000000 --- a/SwiftzTests/MVarSpec.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// MVarSpec.swift -// swiftz -// -// Created by Robert Widmann on 1/19/15. -// Copyright (c) 2015 TypeLift. All rights reserved. -// - -import XCTest -import Swiftz - -class MVarSpec { - func testConcurrentMVar() { - var pingvar: MVar = MVar() - var pongvar: MVar = MVar() - var done: MVar<()> = MVar() - - let ping = Future(exec: gcdExecutionContext, { pingvar.put("hello"); XCTAssert(pongvar.take() == "max", "mvar read"); done.put(()) }()) - let pong = Future(exec: gcdExecutionContext, { XCTAssert(pingvar.take() == "hello", "mvar read"); pongvar.put("max") }()) - - XCTAssert(done.take() == (), "mvar read finished") - XCTAssert(pingvar.isEmpty() && pongvar.isEmpty(), "mvar empty") - } -}