Class Handlers
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 Summary
Modifier and TypeMethodDescriptionstatic org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> alarm(Alarm alarm, Env env, ExecutionCtx ctx) Runs anAlarm.static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> email(Mail mail, MailMessage message, Env env, ExecutionCtx ctx) Runs aMail.static org.teavm.jso.core.JSPromise<Response> fetch(Worker worker, Request request, Env env, ExecutionCtx ctx) Runs aWorker.static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> queue(Consumer<TSObject> consumer, QueueBatch batch, Env env, ExecutionCtx ctx) Runs aConsumer.static org.teavm.jso.core.JSPromise<org.teavm.jso.JSObject> scheduled(Scheduled scheduled, ScheduledController controller, Env env, ExecutionCtx ctx) Runs aScheduled.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 aTail.
-
Method Details
-
fetch
public static org.teavm.jso.core.JSPromise<Response> fetch(Worker worker, Request request, Env env, ExecutionCtx ctx) Runs aWorker.- Parameters:
worker- the handlerrequest- the incoming requestenv- the bindingsctx- 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 aScheduled.- Parameters:
scheduled- the handlercontroller- the Cron Trigger that firedenv- the bindingsctx- 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 aMail.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 handlermessage- the incoming messageenv- the bindingsctx- 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 aConsumer.- Parameters:
consumer- the handlerbatch- the delivered batchenv- the bindingsctx- 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 aTail.- Parameters:
tail- the handlerevents- the trace eventsenv- the bindingsctx- 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 anAlarm.- Parameters:
alarm- the handlerenv- the bindingsctx- the invocation context- Returns:
- a promise that settles when the handler returns
-