Interface NetscriptPort

Object representing a port. A port is a serialized queue.

interface NetscriptPort {
    clear(): void;
    empty(): boolean;
    full(): boolean;
    nextWrite(): Promise<void>;
    peek(): any;
    read(): any;
    tryWrite(value): boolean;
    write(value): any;
}

Methods

  • Check if the port is empty.

    Returns boolean

    true if the port is empty, otherwise false

    Remarks

    RAM cost: 0 GB

  • Check if the port is full.

    Returns boolean

    true if the port is full, otherwise false

    Remarks

    RAM cost: 0 GB

  • Retrieve the first element from the port without removing it.

    Returns any

    the data read

    Remarks

    RAM cost: 0 GB

    This function is used to peek at the data from a port. It returns the first element in the specified port without removing that element. If the port is empty, the string “NULL PORT DATA” will be returned.

  • Shift an element out of the port.

    Returns any

    the data read.

    Remarks

    RAM cost: 0 GB

    This function will remove the first element from the port and return it. If the port is empty, then the string “NULL PORT DATA” will be returned.

  • Attempt to write data to the port.

    Parameters

    • value: any

      Data to write, it's cloned with structuredClone().

    Returns boolean

    True if the data was added to the port, false if the port was full

    Remarks

    RAM cost: 0 GB

  • Write data to a port.

    Parameters

    • value: any

      Data to write, it's cloned with structuredClone().

    Returns any

    The data popped off the queue if it was full.

    Remarks

    RAM cost: 0 GB