Skip to content

[Request]: Optimize MachineList command to fetch machines and default status concurrently #2212

Description

@denizguney

Feature or enhancement request details

Describe the feature / enhancement

In Sources/ContainerCommands/Machine/MachineList.swift, the run() method currently fetches the list of machines (client.list()) and the default machine (client.getDefault()) sequentially.

Using Swift's concurrency (async let), these two asynchronous operations can be executed in parallel to improve command performance and reduce execution latency.

Proposed Solution

Update the run() function to fetch both parameters concurrently:

public func run() async throws {
    let client = MachineClient()
    
    async let machinesTask = client.list()
    async let defaultMachineTask = client.getDefault()
    
    let machines = try await machinesTask
    
    if self.quiet {
        machines.forEach { print($0.id) }
        return
    }
    
    let defaultMachine = try await defaultMachineTask
    try printMachines(machines: machines, format: format, defaultMachine: defaultMachine)
}

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions