All files node.ts

80.95% Statements 34/42
100% Branches 0/0
0% Functions 0/3
80.95% Lines 34/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x           1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x  
import { ActrNode as NativeActrNode } from '../index';
import { callNative } from './error';
import { ActrRef } from './ref';
 
/**
 * ActrNode – an actor node that has not been started yet.
 *
 * Create it from config with `ActrNode.fromConfig()`, then call `start()`.
 */
export class ActrNode {
  constructor(private native: NativeActrNode) {}
 
  /**
   * Create an ActrNode wrapper from `manifest.toml`.
   * The sibling `actr.toml` in the same directory is loaded automatically.
   *
   * @param configPath - Path to manifest.toml
   * @returns ActrNode instance
   */
  static async fromConfig(configPath: string): Promise<ActrNode> {
    const nativeNode = await callNative(() =>
      NativeActrNode.fromFile(configPath),
    );
    return new ActrNode(nativeNode);
  }
 
  /**
   * Start the node and return ActrRef.
   *
   * @returns ActrRef instance for interacting with the actor
   *
   * @example
   * ```typescript
   * const actorRef = await node.start();
   * console.log('Actor started:', actorRef.actorId());
   * ```
   */
  async start(): Promise<ActrRef> {
    const nativeRef = await callNative(() => this.native.start());
    return new ActrRef(nativeRef);
  }
}