0001 // FallibleChannel.swift 0002 // 0003 // The MIT License (MIT) 0004 // 0005 // Copyright (c) 2015 Zewo 0006 // 0007 // Permission is hereby granted, free of charge, to any person obtaining a copy 0008 // of this software and associated documentation files (the "Software"), to deal 0009 // in the Software without restriction, including without limitation the rights 0010 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0011 // copies of the Software, and to permit persons to whom the Software is 0012 // furnished to do so, subject to the following conditions: 0013 // 0014 // The above copyright notice and this permission notice shall be included in all 0015 // copies or substantial portions of the Software. 0016 // 0017 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0018 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0019 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0020 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0021 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0022 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0023 // SOFTWARE. 0024 0025 import CLibvenice 0026 0027 public struct FallibleChannelGenerator<T
FallibleChannel.swift:80 public func generate() -> FallibleChannelGenerator<T> {FallibleChannel.swift:81 return FallibleChannelGenerator(channel: receivingChannel)FallibleReceivingChannel.swift:40 public func generate() -> FallibleChannelGenerator<T> {FallibleReceivingChannel.swift:41 return FallibleChannelGenerator(channel: self)>: GeneratorType { 0028 let channel
FallibleChannel.swift:28 let channel: FallibleReceivingChannel<T>FallibleChannel.swift:30 public mutating func next() -> ChannelResult<T>? {: FallibleReceivingChannel<T> 0029 0030 public mutating func next() -> ChannelResult<T>? { 0031 return channel.receiveResult() 0032 } 0033 } 0034 0035 public enum ChannelResult
FallibleChannel.swift:31 return channel.receiveResult()<T
FallibleChannel.swift:30 public mutating func next() -> ChannelResult<T>? {FallibleChannel.swift:57 private var buffer: [ChannelResult<T>] = []FallibleChannel.swift:96 public func sendResult(result: ChannelResult<T>) {FallibleChannel.swift:106 let result = ChannelResult<T>.Value(value)FallibleChannel.swift:115 let result = ChannelResult<T>.Value(value)FallibleChannel.swift:124 let result = ChannelResult<T>.Error(error)FallibleChannel.swift:133 let result = ChannelResult<T>.Error(error)FallibleChannel.swift:156 public func receiveResult() -> ChannelResult<T>? {FallibleChannel.swift:168 func getResultFromBuffer() -> ChannelResult<T>? {FallibleReceivingChannel.swift:36 public func receiveResult() -> ChannelResult<T>? {FallibleReceivingChannel.swift:52 func getResultFromBuffer() -> ChannelResult<T>? {FallibleSendable.swift:30 func sendResult(result: ChannelResult<T>)FallibleSendable.swift:33 public func <-<W: FallibleSendable>(sender: W, result: ChannelResult<W.T>) {FallibleSendingChannel.swift:32 public func sendResult(result: ChannelResult<T>) {Select.swift:74 var closure: ChannelResult<T> -> VoidSelect.swift:76 init(channel: FallibleChannel<T>, closure: ChannelResult<T> -> Void) {Select.swift:94 var closure: ChannelResult<T> -> VoidSelect.swift:96 init(channel: FallibleReceivingChannel<T>, closure: ChannelResult<T> -> Void) {Select.swift:268 public func receiveFrom<T>(channel: FallibleChannel<T>?, closure: ChannelResult<T> -> Void) {Select.swift:275 public func receiveFrom<T>(channel: FallibleReceivingChannel<T>?, closure: ChannelResult<T> -> Void) {> { 0036 case Value
FallibleChannel.swift:36 case Value(T)FallibleChannel.swift:39 public func success(@noescape closure: T -> Void) {(T) 0037 case Error
FallibleChannel.swift:41 case .Value(let value): closure(value)FallibleChannel.swift:106 let result = ChannelResult<T>.Value(value)FallibleChannel.swift:115 let result = ChannelResult<T>.Value(value)FallibleChannel.swift:147 case .Value(let v): return v(ErrorType) 0038 0039 public func success(@noescape closure: T -> Void) { 0040 switch self { 0041 case .Value(let value): closure(value) 0042 default: break 0043 } 0044 } 0045 0046 public func failure(@noescape closure: ErrorType -> Void) { 0047 switch self { 0048 case .Error(let error): closure(error) 0049 default: break 0050 } 0051 } 0052 } 0053 0054 public final class FallibleChannel
FallibleChannel.swift:48 case .Error(let error): closure(error)FallibleChannel.swift:124 let result = ChannelResult<T>.Error(error)FallibleChannel.swift:133 let result = ChannelResult<T>.Error(error)FallibleChannel.swift:148 case .Error(let e): throw e<T
FallibleReceivingChannel.swift:26 private let channel: FallibleChannel<T>FallibleReceivingChannel.swift:28 init(_ channel: FallibleChannel<T>) {FallibleSendingChannel.swift:26 private let channel: FallibleChannel<T>FallibleSendingChannel.swift:28 init(_ channel: FallibleChannel<T>) {Select.swift:73 let channel: FallibleChannel<T>Select.swift:76 init(channel: FallibleChannel<T>, closure: ChannelResult<T> -> Void) {Select.swift:153 let channel: FallibleChannel<T>Select.swift:157 init(channel: FallibleChannel<T>, value: T, closure: Void -> Void) {Select.swift:193 let channel: FallibleChannel<T>Select.swift:197 init(channel: FallibleChannel<T>, error: ErrorType, closure: Void -> Void) {Select.swift:268 public func receiveFrom<T>(channel: FallibleChannel<T>?, closure: ChannelResult<T> -> Void) {Select.swift:296 public func send<T>(value: T, to channel: FallibleChannel<T>?, closure: Void -> Void) {Select.swift:310 public func throwError<T>(error: ErrorType, into channel: FallibleChannel<T>?, closure: Void -> Void) {>: SequenceType, FallibleSendable, FallibleReceivable { 0055 private let channel
FallibleChannel.swift:57 private var buffer: [ChannelResult<T>] = []FallibleChannel.swift:74 public lazy var sendingChannel: FallibleSendingChannel<T> = FallibleSendingChannel(self)FallibleChannel.swift:77 public lazy var receivingChannel: FallibleReceivingChannel<T> = FallibleReceivingChannel(self)FallibleChannel.swift:80 public func generate() -> FallibleChannelGenerator<T> {FallibleChannel.swift:96 public func sendResult(result: ChannelResult<T>) {FallibleChannel.swift:104 public func send(value: T) {FallibleChannel.swift:113 func send(value: T, clause: UnsafeMutablePointer<Void>, index: Int) {FallibleChannel.swift:140 public func receive() throws -> T? {FallibleChannel.swift:156 public func receiveResult() -> ChannelResult<T>? {FallibleChannel.swift:168 func getResultFromBuffer() -> ChannelResult<T>? {: chan 0056 public var closed
FallibleChannel.swift:66 self.channel = mill_chmake(bufferSize, "FallibleChannel init")FallibleChannel.swift:70 mill_chclose(channel, "FallibleChannel deinit")FallibleChannel.swift:91 mill_chdone(channel, "Channel close")FallibleChannel.swift:99 mill_chs(channel, "FallibleChannel sendResult")FallibleChannel.swift:108 mill_chs(channel, "FallibleChannel send")FallibleChannel.swift:117 mill_choose_out(clause, channel, Int32(index))FallibleChannel.swift:126 mill_chs(channel, "FallibleChannel send")FallibleChannel.swift:135 mill_choose_out(clause, channel, Int32(index))FallibleChannel.swift:144 mill_chr(channel, "FallibleChannel receive")FallibleChannel.swift:160 mill_chr(channel, "FallibleChannel receiveResult")FallibleChannel.swift:165 mill_choose_in(clause, channel, Int32(index)): Bool = false 0057 private var buffer
FallibleChannel.swift:86 if closed {FallibleChannel.swift:90 closed = trueFallibleChannel.swift:97 if !closed {FallibleChannel.swift:105 if !closed {FallibleChannel.swift:114 if !closed {FallibleChannel.swift:123 if !closed {FallibleChannel.swift:132 if !closed {FallibleChannel.swift:141 if closed && buffer.count <= 0 {FallibleChannel.swift:157 if closed && buffer.count <= 0 {FallibleChannel.swift:169 if closed && buffer.count <= 0 {FallibleSendingChannel.swift:53 return channel.closedSelect.swift:297 if let channel = channel where !channel.closed {Select.swift:311 if let channel = channel where !channel.closed {: [ChannelResult<T>] = [] 0058 public let bufferSize
FallibleChannel.swift:98 buffer.append(result)FallibleChannel.swift:107 buffer.append(result)FallibleChannel.swift:116 buffer.append(result)FallibleChannel.swift:125 buffer.append(result)FallibleChannel.swift:134 buffer.append(result)FallibleChannel.swift:141 if closed && buffer.count <= 0 {FallibleChannel.swift:157 if closed && buffer.count <= 0 {FallibleChannel.swift:169 if closed && buffer.count <= 0 {FallibleChannel.swift:172 return buffer.removeFirst(): Int 0059 0060 public convenience init() { 0061 self.init(bufferSize: 0) 0062 } 0063 0064 public init
FallibleChannel.swift:65 self.bufferSize = bufferSize(bufferSize: Int) { 0065 self.bufferSize = bufferSize 0066 self.channel = mill_chmake(bufferSize, "FallibleChannel init") 0067 } 0068 0069 deinit { 0070 mill_chclose(channel, "FallibleChannel deinit") 0071 } 0072 0073 /// Reference that can only send values. 0074 public lazy var sendingChannel: FallibleSendingChannel<T> = FallibleSendingChannel(self) 0075 0076 /// Reference that can only receive values. 0077 public lazy var receivingChannel
FallibleChannel.swift:61 self.init(bufferSize: 0): FallibleReceivingChannel<T> = FallibleReceivingChannel(self) 0078 0079 /// Creates a generator. 0080 public func generate() -> FallibleChannelGenerator<T> { 0081 return FallibleChannelGenerator(channel: receivingChannel) 0082 } 0083 0084 /// Closes the channel. When a channel is closed it cannot receive values anymore. 0085 public func close
FallibleChannel.swift:81 return FallibleChannelGenerator(channel: receivingChannel)() -> Bool { 0086 if closed { 0087 return false 0088 } 0089 0090 closed = true 0091 mill_chdone(channel, "Channel close") 0092 return true 0093 } 0094 0095 /// Send a result to the channel. 0096 public func sendResult
FallibleReceivingChannel.swift:45 return channel.close()(result: ChannelResult<T>) { 0097 if !closed { 0098 buffer.append(result) 0099 mill_chs(channel, "FallibleChannel sendResult") 0100 } 0101 } 0102 0103 /// Send a value to the channel. 0104 public func send
FallibleSendingChannel.swift:33 return channel.sendResult(result)(value: T) { 0105 if !closed { 0106 let result = ChannelResult<T>.Value(value) 0107 buffer.append(result) 0108 mill_chs(channel, "FallibleChannel send") 0109 } 0110 } 0111 0112 /// Send a value from select. 0113 func send
FallibleSendingChannel.swift:37 return channel.send(value)(value: T, clause: UnsafeMutablePointer<Void>, index: Int) { 0114 if !closed { 0115 let result = ChannelResult<T>.Value(value) 0116 buffer.append(result) 0117 mill_choose_out(clause, channel, Int32(index)) 0118 } 0119 } 0120 0121 /// Send an error to the channel. 0122 public func sendError
FallibleSendingChannel.swift:41 return channel.send(value, clause: clause, index: index)Select.swift:164 channel.send(value, clause: clause, index: index)(error: ErrorType) { 0123 if !closed { 0124 let result = ChannelResult<T>.Error(error) 0125 buffer.append(result) 0126 mill_chs(channel, "FallibleChannel send") 0127 } 0128 } 0129 0130 /// Send an error from select. 0131 func send
FallibleSendingChannel.swift:45 return channel.sendError(error)(error: ErrorType, clause: UnsafeMutablePointer<Void>, index: Int) { 0132 if !closed { 0133 let result = ChannelResult<T>.Error(error) 0134 buffer.append(result) 0135 mill_choose_out(clause, channel, Int32(index)) 0136 } 0137 } 0138 0139 /// Receive a value from channel. 0140 public func receive
FallibleSendingChannel.swift:49 return channel.send(error, clause: clause, index: index)Select.swift:204 channel.send(error, clause: clause, index: index)() throws -> T? { 0141 if closed && buffer.count <= 0 { 0142 return nil 0143 } 0144 mill_chr(channel, "FallibleChannel receive") 0145 if let value = getResultFromBuffer() { 0146 switch value { 0147 case .Value(let v): return v 0148 case .Error(let e): throw e 0149 } 0150 } else { 0151 return nil 0152 } 0153 } 0154 0155 /// Receive a result from channel. 0156 public func receiveResult
FallibleReceivingChannel.swift:33 return try channel.receive()() -> ChannelResult<T>? { 0157 if closed && buffer.count <= 0 { 0158 return nil 0159 } 0160 mill_chr(channel, "FallibleChannel receiveResult") 0161 return getResultFromBuffer() 0162 } 0163 0164 func registerReceive
FallibleReceivingChannel.swift:37 return channel.receiveResult()(clause: UnsafeMutablePointer<Void>, index: Int) { 0165 mill_choose_in(clause, channel, Int32(index)) 0166 } 0167 0168 func getResultFromBuffer
FallibleReceivingChannel.swift:49 return channel.registerReceive(clause, index: index)Select.swift:82 channel.registerReceive(clause, index: index)() -> ChannelResult<T>? { 0169 if closed && buffer.count <= 0 { 0170 return nil 0171 } 0172 return buffer.removeFirst() 0173 } 0174 0175 }
FallibleChannel.swift:145 if let value = getResultFromBuffer() {FallibleChannel.swift:161 return getResultFromBuffer()FallibleReceivingChannel.swift:53 return channel.getResultFromBuffer()Select.swift:86 if let result = channel.getResultFromBuffer() {