const std    = @import("std");
const shared = @import("shared");

const ConnectState = union(enum) {
    disconnected,
    connecting,
    connected: std.net.Stream,
    err: anyerror,
};

const Client = struct {
    state: ConnectState = .disconnected,

    pub fn startConnect(self: *Client, addr: std.net.Address) void {
        if (self.state == .connecting or self.state == .connected)
            return;

        self.state = .connecting;

        const stream = std.net.tcpConnectToAddress(addr) catch |err| {
            self.state = .{ .err = err };
            return;
        };

        self.state = .{ .connected = stream };
    }
};
