@@ -140,14 +140,14 @@ public List<CheckedConsumer<Jooby>> stopTasks() {
140140 }
141141
142142 @ Override
143- public Env onStop (final CheckedRunnable task ) {
144- this .shutdown .add (e -> task . run () );
143+ public Env onStop (final CheckedConsumer < Jooby > task ) {
144+ this .shutdown .add (task );
145145 return this ;
146146 }
147147
148148 @ Override
149- public Env onStart (final CheckedRunnable task ) {
150- this .start .add (e -> task . run () );
149+ public Env onStart (final CheckedConsumer < Jooby > task ) {
150+ this .start .add (task );
151151 return this ;
152152 }
153153
@@ -373,7 +373,37 @@ default <T> Option<T> when(final Predicate<String> predicate, final T result) {
373373 * @param task Task to run.
374374 * @return This env.
375375 */
376- Env onStart (CheckedRunnable task );
376+ Env onStart (CheckedConsumer <Jooby > task );
377+
378+ /**
379+ * Add a start task, useful for initialize and/or start services at startup time.
380+ *
381+ * You should ONLY call this method while the application is been initialized, usually executing
382+ * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}.
383+ *
384+ * The behaviour of this method once application has been initialized is <code>undefined</code>.
385+ *
386+ * @param task Task to run.
387+ * @return This env.
388+ */
389+ default Env onStart (final CheckedRunnable task ) {
390+ return onStart (app -> task .run ());
391+ }
392+
393+ /**
394+ * Add a stop task, useful for cleanup and/or stop service at stop time.
395+ *
396+ * You should ONLY call this method while the application is been initialized, usually executing
397+ * {@link Jooby.Module#configure(Env, Config, com.google.inject.Binder)}.
398+ *
399+ * The behaviour of this method once application has been initialized is <code>undefined</code>.
400+ *
401+ * @param task Task to run.
402+ * @return This env.
403+ */
404+ default Env onStop (final CheckedRunnable task ) {
405+ return onStop (app -> task .run ());
406+ }
377407
378408 /**
379409 * Add a stop task, useful for cleanup and/or stop service at stop time.
@@ -386,7 +416,7 @@ default <T> Option<T> when(final Predicate<String> predicate, final T result) {
386416 * @param task Task to run.
387417 * @return This env.
388418 */
389- Env onStop (CheckedRunnable task );
419+ Env onStop (CheckedConsumer < Jooby > task );
390420
391421 /**
392422 * @return List of start tasks.
0 commit comments