File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -235,6 +235,31 @@ declare module 'meteor/meteor' {
235235 * @param func The function to run
236236 */
237237 function defer ( func : Function ) : void ;
238+
239+ /**
240+ * Wrap a function so that it only runs in background in specified environments..
241+ * @param func The function to wrap
242+ * @param options An object with an `on` property that is an array of environment names: `"development"`, `"production"`, and/or `"test"`.
243+ */
244+ function deferrable < T > (
245+ func : ( ) => T ,
246+ options : { on : Array < "development" | "production" | "test" > }
247+ ) : T | void ;
248+
249+ /**
250+ * Wrap a function to run in the background in development (similar to Meteor.isDevelopment ? Meteor.defer(fn) : Meteor.startup(fn)).
251+ * @param func The function to wrap
252+ */
253+ function deferDev < T > (
254+ func : ( ) => T
255+ ) : T | void ;
256+ /**
257+ * Wrap a function to run in the background in production (similar to Meteor.isProduction ? Meteor.defer(fn) : Meteor.startup(fn)).
258+ * @param func The function to wrap
259+ */
260+ function deferProd < T > (
261+ func : ( ) => T
262+ ) : T | void ;
238263 /** Timeout **/
239264
240265 /** utils **/
Original file line number Diff line number Diff line change @@ -88,6 +88,12 @@ namespace MeteorTests {
8888 . aggregate ( [ { $group : { _id : null , names : { $addToSet : '$name' } } } ] )
8989 . toArray ( )
9090 . then ( ) ;
91+
92+ Meteor . deferrable (
93+ ( ) => console . log ( 'This is deferred until after startup.' ) ,
94+ { on : [ 'development' , 'test' ] } ,
95+ )
96+
9197 } ) ;
9298 }
9399
@@ -398,6 +404,7 @@ namespace MeteorTests {
398404 if ( Meteor . isServer ) {
399405 Logs . remove ( { } ) ;
400406 Players . remove ( { karma : { $lt : - 2 } } ) ;
407+ Meteor . defer ( ( ) => console . log ( 'Old low-karma players removed from the Players collection.' ) ) ;
401408 }
402409 } ) ;
403410
@@ -1203,6 +1210,14 @@ namespace MeteorTests {
12031210 Rooms . _dropIndex ( 'indexName' ) ;
12041211 }
12051212
1213+ Meteor . deferDev ( ( ) => {
1214+ console . log ( 'This is a development-only deferred function.' ) ;
1215+ } ) ;
1216+
1217+ Meteor . deferProd ( ( ) => {
1218+ console . log ( 'This is a production-only deferred function.' ) ;
1219+ } ) ;
1220+
12061221 ( async function ( ) {
12071222 await Rooms . dropIndexAsync ( 'indexName' ) ;
12081223 } ) ( ) ;
You can’t perform that action at this time.
0 commit comments