Class Handlers

java.lang.Object
dev.gmitch215.bytebox.Handlers

public final class Handlers extends Object
What a generated entry point calls.

The plugin emits one exported static method per trigger the handler class implements, and each is a single call into here. Nothing in this class is meant to be called by hand, but the shape is worth knowing because it explains how a blocking handler works at all.

Each method starts the handler on a fiber and hands JavaScript a promise straight away. The fiber is what makes suspension legal, since a stack with a JavaScript frame in it cannot suspend, and the promise is what tells the host when the handler has genuinely finished rather than merely parked. The host drains its queue to start the fiber, then awaits the promise.

Since:
1.0.0
  • Method Details

    • fetch

      public static org.teavm.jso.core.JSPromise<Response> fetch(Worker worker, Request request, Env env, ExecutionCtx ctx)
      Runs a Worker.
      Parameters:
      worker - the handler
      request - the incoming request
      env - the bindings
      ctx - the invocation context
      Returns:
      the response, once the handler has produced one
    • scheduled

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> scheduled(Scheduled scheduled, ScheduledController controller, Env env, ExecutionCtx ctx)
      Runs a Scheduled.
      Parameters:
      scheduled - the handler
      controller - the Cron Trigger that fired
      env - the bindings
      ctx - the invocation context
      Returns:
      a promise that settles when the handler returns
    • email

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> email(Mail mail, MailMessage message, Env env, ExecutionCtx ctx)
      Runs a Mail.

      Raises when the handler returns without acting on the message, because Cloudflare drops an unacted message silently. InboundMail.drop() is how a handler says the silence was meant.

      Parameters:
      mail - the handler
      message - the incoming message
      env - the bindings
      ctx - the invocation context
      Returns:
      a promise that settles when the handler returns
    • queue

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> queue(Consumer<TSObject> consumer, QueueBatch batch, Env env, ExecutionCtx ctx)
      Runs a Consumer.
      Parameters:
      consumer - the handler
      batch - the delivered batch
      env - the bindings
      ctx - the invocation context
      Returns:
      a promise that settles when the handler returns
    • tail

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> tail(Tail tail, org.teavm.jso.core.JSArrayReader<TraceItem> events, Env env, ExecutionCtx ctx)
      Runs a Tail.
      Parameters:
      tail - the handler
      events - the trace events
      env - the bindings
      ctx - the invocation context
      Returns:
      a promise that settles when the handler returns
    • alarm

      public static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> alarm(Alarm alarm, Env env, ExecutionCtx ctx)
      Runs an Alarm.
      Parameters:
      alarm - the handler
      env - the bindings
      ctx - the invocation context
      Returns:
      a promise that settles when the handler returns