import { RemoteActorContext } from "#behavior/context/server/RemoteActorContext.js";
import { NotImplementedError } from "#general";
import {
  ServerInteraction
} from "#protocol";
class OnlineServerInteraction {
  #interaction;
  constructor(node) {
    this.#interaction = new ServerInteraction(node);
  }
  async *read(request, context) {
    const session = RemoteActorContext(context).beginReadOnly();
    try {
      for await (const report of this.#interaction.read(request, session)) {
        yield report;
      }
    } finally {
      session[Symbol.dispose]();
    }
  }
  subscribe(_request, _context) {
    throw new NotImplementedError("subscribe not implemented");
  }
  async write(request, context) {
    return RemoteActorContext(context).act((session) => this.#interaction.write(request, session));
  }
  async *invoke(request, context) {
    const session = RemoteActorContext({ ...context, command: true }).open();
    try {
      for await (const chunk of this.#interaction.invoke(request, session)) {
        yield chunk;
      }
    } catch (error) {
      await session.reject(error);
    }
    return session.resolve(void 0);
  }
}
export {
  OnlineServerInteraction
};
//# sourceMappingURL=OnlineServerInteraction.js.map
