0001    // Channel.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 ChannelGenerator
Channel.swift:65
    public func generate() -> ChannelGenerator<T> {
Channel.swift:66
        return ChannelGenerator(channel: receivingChannel)
ReceivingChannel.swift:36
    public func generate() -> ChannelGenerator<T> {
ReceivingChannel.swift:37
        return ChannelGenerator(channel: self)
<T
Channel.swift:28
    let channel: ReceivingChannel<T>
Channel.swift:30
    public mutating func next() -> T? {
>: GeneratorType { 0028 let channel
Channel.swift:31
        return channel.receive()
: ReceivingChannel<T> 0029 0030 public mutating func next() -> T? { 0031 return channel.receive() 0032 } 0033 } 0034 0035 public final class Channel
ReceivingChannel.swift:26
    private let channel: Channel<T>
ReceivingChannel.swift:28
    init(_ channel: Channel<T>) {
SendingChannel.swift:26
    private let channel: Channel<T>
SendingChannel.swift:28
    init(_ channel: Channel<T>) {
Select.swift:33
    let channel: Channel<T>
Select.swift:36
    init(channel: Channel<T>, closure: T -> Void) {
Select.swift:113
    let channel: Channel<T>
Select.swift:117
    init(channel: Channel<T>, value: T, closure: Void -> Void) {
Select.swift:233
    let channel: Channel<T>
Select.swift:236
    init(channel: Channel<T>, closure: Void -> Void) {
Select.swift:254
    public func receiveFrom<T>(channel: Channel<T>?, closure: T -> Void) {
Select.swift:282
    public func send<T>(value: T, to channel: Channel<T>?, closure: Void -> Void) {
Select.swift:325
        let done = Channel<Bool>()
Ticker.swift:26
    private let internalChannel = Channel<Int64>()
Timer.swift:26
    private var internalChannel = Channel<Void>()
<T
Channel.swift:38
    private var buffer: [T] = []
Channel.swift:59
    public lazy var sendingChannel: SendingChannel<T> = SendingChannel(self)
Channel.swift:62
    public lazy var receivingChannel: ReceivingChannel<T> = ReceivingChannel(self)
Channel.swift:65
    public func generate() -> ChannelGenerator<T> {
Channel.swift:81
    public func send(value: T) {
Channel.swift:89
    func send(value: T, clause: UnsafeMutablePointer<Void>, index: Int) {
Channel.swift:97
    public func receive() -> T? {
Channel.swift:109
    func getValueFromBuffer() -> T? {
>: SequenceType, Sendable, Receivable { 0036 private let channel
Channel.swift:51
        self.channel = mill_chmake(bufferSize, "Channel init")
Channel.swift:55
        mill_chclose(channel, "Channel deinit")
Channel.swift:76
        mill_chdone(channel, "Channel close")
Channel.swift:84
            mill_chs(channel, "Channel send")
Channel.swift:92
            mill_choose_out(clause, channel, Int32(index))
Channel.swift:101
        mill_chr(channel, "Channel receive")
Channel.swift:106
        mill_choose_in(clause, channel, Int32(index))
: chan 0037 public var closed
Channel.swift:71
        if closed {
Channel.swift:75
        closed = true
Channel.swift:82
        if !closed {
Channel.swift:90
        if !closed {
Channel.swift:98
        if closed && buffer.count <= 0 {
Channel.swift:110
        if closed && buffer.count <= 0 {
SendingChannel.swift:41
        return channel.closed
Select.swift:283
        if let channel = channel where !channel.closed {
: Bool = false 0038 private var buffer
Channel.swift:83
            buffer.append(value)
Channel.swift:91
            buffer.append(value)
Channel.swift:98
        if closed && buffer.count <= 0 {
Channel.swift:110
        if closed && buffer.count <= 0 {
Channel.swift:113
        return buffer.removeFirst()
: [T] = [] 0039 public let bufferSize
Channel.swift:42
        return bufferSize > 0
Channel.swift:50
        self.bufferSize = bufferSize
: Int 0040 0041 public var isBuffered: Bool { 0042 return bufferSize > 0 0043 } 0044 0045 public convenience init() { 0046 self.init(bufferSize: 0) 0047 } 0048 0049 public init
Channel.swift:46
        self.init(bufferSize: 0)
(bufferSize: Int) { 0050 self.bufferSize = bufferSize 0051 self.channel = mill_chmake(bufferSize, "Channel init") 0052 } 0053 0054 deinit { 0055 mill_chclose(channel, "Channel deinit") 0056 } 0057 0058 /// Reference that can only send values. 0059 public lazy var sendingChannel: SendingChannel<T> = SendingChannel(self) 0060 0061 /// Reference that can only receive values. 0062 public lazy var receivingChannel
Channel.swift:66
        return ChannelGenerator(channel: receivingChannel)
Ticker.swift:30
        return internalChannel.receivingChannel
Timer.swift:30
        return internalChannel.receivingChannel
: ReceivingChannel<T> = ReceivingChannel(self) 0063 0064 /// Creates a generator. 0065 public func generate() -> ChannelGenerator<T> { 0066 return ChannelGenerator(channel: receivingChannel) 0067 } 0068 0069 /// Closes the channel. When a channel is closed it cannot receive values anymore. 0070 public func close
ReceivingChannel.swift:41
        return channel.close()
() -> Bool { 0071 if closed { 0072 return false 0073 } 0074 0075 closed = true 0076 mill_chdone(channel, "Channel close") 0077 return true 0078 } 0079 0080 /// Send a value to the channel. 0081 public func send
SendingChannel.swift:33
        return channel.send(value)
(value: T) { 0082 if !closed { 0083 buffer.append(value) 0084 mill_chs(channel, "Channel send") 0085 } 0086 } 0087 0088 /// Send a value from select. 0089 func send
SendingChannel.swift:37
        return channel.send(value, clause: clause, index: index)
Select.swift:124
        channel.send(value, clause: clause, index: index)
(value: T, clause: UnsafeMutablePointer<Void>, index: Int) { 0090 if !closed { 0091 buffer.append(value) 0092 mill_choose_out(clause, channel, Int32(index)) 0093 } 0094 } 0095 0096 /// Receives a value from the channel. 0097 public func receive
ReceivingChannel.swift:33
        return channel.receive()
() -> T? { 0098 if closed && buffer.count <= 0 { 0099 return nil 0100 } 0101 mill_chr(channel, "Channel receive") 0102 return getValueFromBuffer() 0103 } 0104 0105 func registerReceive
ReceivingChannel.swift:45
        return channel.registerReceive(clause, index: index)
Select.swift:42
        channel.registerReceive(clause, index: index)
Select.swift:242
        channel.registerReceive(clause, index: index)
(clause: UnsafeMutablePointer<Void>, index: Int) { 0106 mill_choose_in(clause, channel, Int32(index)) 0107 } 0108 0109 func getValueFromBuffer
Channel.swift:102
        return getValueFromBuffer()
ReceivingChannel.swift:49
        return channel.getValueFromBuffer()
Select.swift:46
        if let value = channel.getValueFromBuffer() {
() -> T? { 0110 if closed && buffer.count <= 0 { 0111 return nil 0112 } 0113 return buffer.removeFirst() 0114 } 0115 }