Skip to main content
Module

x/vim_channel_command/mod.ts>Session

🦕 Vim's Channel command for Deno
Latest
class Session
import { Session } from "https://deno.land/x/vim_channel_command@v3.1.1/mod.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. If the session is not running, the promise will be rejected with Error.

recv(msgid: number): Promise<Message>

Receive a message from the peer. If the session is not running or the message ID is already reserved, the promise will be rejected with Error.

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

Send a command or a message to the peer. If the session is not running, the promise will be rejected with Error.

shutdown(): Promise<void>

Shutdown the session. If the session is not running, the promise will be rejected with Error.

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. If the session is not running, the promise will be rejected with Error.