Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/pup/lib/common/ipc.ts>FileIPC

Universal process manager built in Deno
Go to Latest
class FileIPC
import { FileIPC } from "https://deno.land/x/pup@1.0.0-rc.10/lib/common/ipc.ts";

Constructors

new
FileIPC(
filePath: string,
staleMessageLimitMs?: number,
debounceTimeMs?: number,
)

Properties

private
aborted: boolean
private
debounceTimeMs: number
private
dirPath: string
private
fileName: string
private
filePath: string
private
messageQueue: IpcValidatedMessage[][]
private
staleMessageLimitMs: number
private
optional
watcher: Deno.FsWatcher
MAX_DATA_LENGTH: number

Methods

extractMessages is a private helper function that reads from the IPC file, validates the messages and returns them as an array of IpcValidatedMessage. It also handles the removal of the file after reading and validates the data based on the staleMessageLimitMs.

This function is called every time a 'modify' event is detected by the file watcher started in startWatching method.

Note: This function should only be used internally by the FileIPC class and is not meant to be exposed to external consumers.

private
startWatching()

startWatching method initiates a file watcher on the filePath. When a file modification event occurs, it will debounce the call to extractMessages to ensure it doesn't get called more than once in a short amount of time (as specified by debounceTimeMs). The received messages from the extractMessages call are then added to the messageQueue to be consumed by the receiveData generator.

close(leaveFile?: boolean): Promise<void>

Close the file-based IPC and remove the IPC file.

getFilePath(): string
receiveData(): AsyncGenerator<IpcValidatedMessage[], void, unknown>
sendData(data: string): Promise<void>

Send data using the file-based IPC.

Will append to file in this.filePath if it exists, otherwise create a new one