0001 // Co.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 /// Current time. 0028 public var now: Int64 { 0029 return CLibvenice.now() 0030 } 0031 0032 public let hour
Coroutine.swift:92 mill_msleep(now + duration, "nap")Ticker.swift:38 self.internalChannel <- now: Int64 = 3600000 0033 public let hours = hour 0034 public let minute
Coroutine.swift:33 public let hours = hour: Int64 = 60000 0035 public let minutes = minute 0036 public let second
Coroutine.swift:35 public let minutes = minute: Int64 = 1000 0037 public let seconds = second 0038 public let millisecond
Coroutine.swift:37 public let seconds = second: Int64 = 1 0039 public let milliseconds = millisecond 0040 0041 public typealias Deadline
Coroutine.swift:39 public let milliseconds = millisecond= Int64 0042 public let never
Coroutine.swift:42 public let never: Deadline = -1Coroutine.swift:96 public func wakeUp(deadline: Deadline) {Poll.swift:54 public func poll(fileDescriptor: FileDescriptor, events: PollEvent, deadline: Deadline = never) -> PollResult {Select.swift:324 public func timeout(deadline: Deadline, closure: Void -> Void) {Timer.swift:33 public init(deadline: Deadline) {: Deadline = -1 0043 public let noDeadline = never 0044 0045 public typealias Duration
Coroutine.swift:43 public let noDeadline = neverPoll.swift:54 public func poll(fileDescriptor: FileDescriptor, events: PollEvent, deadline: Deadline = never) -> PollResult {= Int64 0046 public typealias PID
Coroutine.swift:65 public func after(napDuration: Duration, routine: Void -> Void) {Coroutine.swift:73 public func every(napDuration: Duration, routine: (done: Void -> Void) -> Void) {Coroutine.swift:91 public func nap(duration: Duration) {= pid_t 0047 0048 /// Runs the expression in a lightweight coroutine. 0049 public func co
Coroutine.swift:106 public func fork() -> PID {(routine: Void -> Void) { 0050 var _routine = routine 0051 CLibvenice.co(&_routine, { routinePointer in 0052 UnsafeMutablePointer<(Void -> Void)>(routinePointer).memory() 0053 }, "co") 0054 } 0055 0056 /// Runs the expression in a lightweight coroutine. 0057 public func co
Coroutine.swift:66 co {Coroutine.swift:74 co {Select.swift:326 co {Ticker.swift:34 co {Timer.swift:34 co {(@autoclosure(escaping) routine: Void -> Void) { 0058 var _routine: Void -> Void = routine 0059 CLibvenice.co(&_routine, { routinePointer in 0060 UnsafeMutablePointer<(Void -> Void)>(routinePointer).memory() 0061 }, "co") 0062 } 0063 0064 /// Runs the expression in a lightweight coroutine after the given duration. 0065 public func after(napDuration: Duration, routine: Void -> Void) { 0066 co { 0067 nap(napDuration) 0068 routine() 0069 } 0070 } 0071 0072 /// Runs the expression in a lightweight coroutine periodically. Call done() to leave the loop. 0073 public func every(napDuration: Duration, routine: (done: Void -> Void) -> Void) { 0074 co { 0075 var done = false 0076 while !done { 0077 nap(napDuration) 0078 routine { 0079 done = true 0080 } 0081 } 0082 } 0083 } 0084 0085 /// Preallocates coroutine stacks. Returns the number of stacks that it actually managed to allocate. 0086 public func preallocateCoroutineStacks(stackCount stackCount: Int, stackSize: Int) { 0087 return goprepare(Int32(stackCount), stackSize) 0088 } 0089 0090 /// Sleeps for duration. 0091 public func nap
Once.swift:38 co(f())(duration: Duration) { 0092 mill_msleep(now + duration, "nap") 0093 } 0094 0095 /// Wakes up at deadline. 0096 public func wakeUp
Coroutine.swift:67 nap(napDuration)Coroutine.swift:77 nap(napDuration)Ticker.swift:36 nap(period)(deadline: Deadline) { 0097 mill_msleep(deadline, "wakeUp") 0098 } 0099 0100 /// Passes control to other coroutines. 0101 public var yield: Void { 0102 mill_yield("yield") 0103 } 0104 0105 /// Fork the current process. 0106 public func fork() -> PID { 0107 return mfork() 0108 } 0109 0110 /// Get the number of logical CPU cores available. This might return a bigger number than the physical CPU Core number if the CPU supports hyper-threading. 0111 public var CPUCoreCount: Int { 0112 return Int(mill_number_of_cores()) 0113 } 0114 0115 public func dump() { 0116 goredump() 0117 } 0118 0119 infix operator <- {} 0120 prefix operator <- {} 0121 prefix operator !<- {} 0122
Select.swift:327 wakeUp(deadline)Timer.swift:35 wakeUp(deadline)