Class DurableHandlers

java.lang.Object
dev.gmitch215.bytebox.durable.DurableHandlers

public final class DurableHandlers extends Object
What the generated Durable Object exports call.

The generated JavaScript class the runtime instantiates forwards each method here with the instance's identifier, and each one starts the handler on a fiber and hands JavaScript a promise. A handler cannot be called directly from a promise executor, because an executor cannot suspend and every binding call does.

Not part of the surface a project writes against. It is public because generated code in another package calls it.

Since:
1.0.0
  • Method Details

    • instance

      public static <T> T instance(String identifier, Supplier<T> factory)
      The instance for an identifier, built on first use.
      Type Parameters:
      T - the object's type
      Parameters:
      identifier - the Durable Object's identifier
      factory - how to build one
      Returns:
      the instance
    • fetch

      public static org.teavm.jso.core.JSPromise<Response> fetch(DurableObject object, Request request, DurableState state, Env env)
      Runs a request.
      Parameters:
      object - the instance
      request - the request
      state - the instance's context
      env - the bindings
      Returns:
      the response, once the handler has produced one
    • alarm

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> alarm(AlarmObject object, DurableState state, Env env)
      Runs an alarm.
      Parameters:
      object - the instance
      state - the instance's context
      env - the bindings
      Returns:
      a promise that settles when the handler returns
    • message

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> message(SocketObject object, WebSocket socket, String text, DurableState state, Env env)
      Runs a text message.
      Parameters:
      object - the instance
      socket - which connection sent it
      text - the message
      state - the instance's context
      env - the bindings
      Returns:
      a promise that settles when the handler returns
    • message

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> message(SocketObject object, WebSocket socket, org.teavm.jso.typedarrays.ArrayBuffer bytes, DurableState state, Env env)
      Runs a binary message.
      Parameters:
      object - the instance
      socket - which connection sent it
      bytes - the message
      state - the instance's context
      env - the bindings
      Returns:
      a promise that settles when the handler returns
    • closed

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> closed(SocketObject object, WebSocket socket, int code, String reason, boolean clean, DurableState state, Env env)
      Runs a close.
      Parameters:
      object - the instance
      socket - which connection closed
      code - the close code
      reason - the close reason
      clean - whether the peer closed properly
      state - the instance's context
      env - the bindings
      Returns:
      a promise that settles when the handler returns
    • failed

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> failed(SocketObject object, WebSocket socket, String message, DurableState state, Env env)
      Runs a failure.
      Parameters:
      object - the instance
      socket - which connection failed
      message - what went wrong
      state - the instance's context
      env - the bindings
      Returns:
      a promise that settles when the handler returns