Skip to main content
Glama
TaskManager.swiftβ€’2.3 kB
import Foundation public class TaskManager { private var isServerRunning = false public init() {} public func executeQuickTask(name: String, duration: Int, verbose: Bool) async { if verbose { print("πŸ“ Task '\(name)' started at \(Date())") } // Simulate work with periodic output using Swift Concurrency for i in 1...duration { if verbose { print("βš™οΈ Working... step \(i)/\(duration)") } try? await Task.sleep(for: .seconds(1)) } if verbose { print("πŸŽ‰ Task '\(name)' completed at \(Date())") } else { print("Task '\(name)' completed in \(duration)s") } } public func startLongRunningServer(port: Int, verbose: Bool, autoShutdown: Int) async { if verbose { print("πŸ”§ Initializing server on port \(port)...") } var secondsRunning = 0 let startTime = Date() isServerRunning = true // Simulate server startup try? await Task.sleep(for: .milliseconds(500)) print("βœ… Server running on port \(port)") // Main server loop using Swift Concurrency while isServerRunning { try? await Task.sleep(for: .seconds(1)) secondsRunning += 1 if verbose && secondsRunning % 5 == 0 { print("πŸ“Š Server heartbeat: \(secondsRunning)s uptime") } // Handle auto-shutdown if autoShutdown > 0 && secondsRunning >= autoShutdown { if verbose { print("⏰ Auto-shutdown triggered after \(autoShutdown)s") } break } } let uptime = Date().timeIntervalSince(startTime) print("πŸ›‘ Server stopped after \(String(format: "%.1f", uptime))s uptime") isServerRunning = false } public func stopServer() { isServerRunning = false } public func calculateSum(_ a: Int, _ b: Int) -> Int { return a + b } public func validateInput(_ input: String) -> Bool { return !input.isEmpty && input.count <= 100 } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cameroncooke/XcodeBuildMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server