@@ -128,6 +128,7 @@ export class Federation<TContextData> {
128128 #kv: KvStore ;
129129 #kvPrefixes: FederationKvPrefixes ;
130130 #queue?: MessageQueue ;
131+ #queueStarted: boolean ;
131132 #router: Router ;
132133 #nodeInfoDispatcher?: NodeInfoDispatcher < TContextData > ;
133134 #actorCallbacks?: ActorCallbacks < TContextData > ;
@@ -170,6 +171,7 @@ export class Federation<TContextData> {
170171 ...( kvPrefixes ?? { } ) ,
171172 } ;
172173 this . #queue = queue ;
174+ this . #queueStarted = false ;
173175 this . #router = new Router ( ) ;
174176 this . #router. add ( "/.well-known/webfinger" , "webfinger" ) ;
175177 this . #router. add ( "/.well-known/nodeinfo" , "nodeInfoJrd" ) ;
@@ -191,8 +193,13 @@ export class Federation<TContextData> {
191193 15 * 60_000 ,
192194 60 * 60_000 ,
193195 ] . map ( ( ms ) => Temporal . Duration . from ( { milliseconds : ms } ) ) ;
196+ }
194197
195- queue ?. listen ( this . #listenQueue. bind ( this ) ) ;
198+ #startQueue( ) {
199+ if ( this . #queue != null && ! this . #queueStarted) {
200+ this . #queue?. listen ( this . #listenQueue. bind ( this ) ) ;
201+ this . #queueStarted = true ;
202+ }
196203 }
197204
198205 async #listenQueue( message : OutboxMessage ) : Promise < void > {
@@ -715,6 +722,7 @@ export class Federation<TContextData> {
715722 "The activity to send must have at least one actor property." ,
716723 ) ;
717724 }
725+ this . #startQueue( ) ;
718726 if ( activity . id == null ) {
719727 activity = activity . clone ( {
720728 id : new URL ( `urn:uuid:${ crypto . randomUUID ( ) } ` ) ,
@@ -798,6 +806,7 @@ export class Federation<TContextData> {
798806 contextData,
799807 } : FederationFetchOptions < TContextData > ,
800808 ) : Promise < Response > {
809+ this . #startQueue( ) ;
801810 onNotFound ??= notFound ;
802811 onNotAcceptable ??= notAcceptable ;
803812 const url = new URL ( request . url ) ;
0 commit comments