Skip to main content
Module

x/vim_channel_command/session.ts>Session

🦕 Vim's Channel command for Deno
Go to Latest
class Session
import { Session } from "https://deno.land/x/vim_channel_command@v3.0.0/session.ts";

Session is a wrapper of ReadableStream and WritableStream to send commands and receive messages.

Examples

Example 1

import { Session } from "./mod.ts";

const session = new Session(
  Deno.stdin.readable,
  Deno.stdout.writable,
);
session.onMessage = (message) => {
  console.log("Recv:", message);
};
session.start();

// ...

await session.shutdown();

Constructors

new
Session(reader: ReadableStream<Uint8Array>, writer: WritableStream<Uint8Array>)

Constructs a new session.

Properties

optional
onInvalidMessage: (message: unknown) => void

The callback function to be called when an invalid message is received. The default behavior is to ignore the message.

optional
onMessage: (message: Message) => void

The callback function to be called when a message is received. The default behavior is to ignore the message.

Methods

forceShutdown(): Promise<void>

Shutdown the session forcibly.

recv(msgid: number): Promise<Message>

Receive a message from the peer.

send(data: Command | Message): Promise<void>

Send a command or a message to the peer.

shutdown(): Promise<void>

Shutdown the session.

start(): void

Start the session.

This method must be called before calling send or recv. If the session is already running, this method throws an error.

The session is started in the following steps:

wait(): Promise<void>

Wait until the session is shutdown.