Created
November 29, 2022 21:56
-
-
Save jbadger3/1c48673f9f1fd1fe5f79e0b39ef7bbf0 to your computer and use it in GitHub Desktop.
A swift script used to demonstrate stream buffering and flushing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/swift | |
import Foundation | |
let arguments = CommandLine.arguments | |
let startingValue = Int(arguments[1])! | |
var flush = false | |
if arguments.count == 3 { | |
flush = arguments[2] == "-f" ? true : false | |
} | |
countDown(from: startingValue, flush: flush) | |
func countDown(from count: Int, flush: Bool = false) { | |
for i in (1...count).reversed() { | |
print(i) | |
if flush { | |
fflush(stdout) | |
} | |
Thread.sleep(forTimeInterval: 1.0) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment