'use strict';

let eggUtils = require('egg-core').utils;
if (!eggUtils) {
  // try to support egg-core@3
  eggUtils = require('egg-core/lib/utils');
}

module.exports = {
  runInBackground(scope) {
    /* istanbul ignore next */
    const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
    scope._name = taskName;
    const promise = this._runInBackground(scope);
    this.app._backgroundTasks.push(promise);
  },
};

@@ -12,11 +12,113 @@
 ';%0A%0A
-let
+// try to use eggUtils.getCalleeFromStack%0A// ignore it if egg-core module not found%0Alet eggUtils;%0Atry %7B%0A 
  egg
@@ -152,16 +152,18 @@
 .utils;%0A
+  
 if (!egg
@@ -171,16 +171,18 @@
 tils) %7B%0A
+  
   // try
@@ -206,16 +206,18 @@
 ore@3%0A  
+ 
+ 
 eggUtils
@@ -250,16 +250,55 @@
 tils');%0A
+  %7D%0A%7D catch (_) %7B%0A  // ignore eggUtils%0A
 %7D%0A%0Amodul
@@ -418,16 +418,29 @@
 .name %7C%7C
+ (eggUtils &&
  eggUtil
@@ -465,18 +465,41 @@
 ck(true)
+)
 ;%0A
+    if (taskName) %7B%0A  
     scop
@@ -518,16 +518,23 @@
 skName;%0A
+    %7D%0A%0A
     cons

allow egg-core module missing (#83)