Inject functions that return strings.

@param {Object} funcs reference
@param {Object} task collection
437046
function injectStrings (funcs, task) {
  /**
   * Inject a function that returns a string.
   */

  function inject (taskKey) {
    var taskName = task[taskKey]

    if (regexQuoted.test(taskName)) {
      funcs[taskName] = function () {
        return taskName.substr(1, taskName.length - 2)
      }
    }
  }

  Object.keys(task)
    .forEach(inject)
}
1017574
def execute(function, name):
    
    try:
        return TaskResult(name, True, None, function())
    except Exception as exc:
        return TaskResult(name, False, exc, None)
1315854
def _taskify(func):
	''''''
	if not isinstance(func, _Task):
		func = _Task(func)

		spec = inspect.getargspec(func.func)
		if spec.args:
			num_args = len(spec.args)
			num_kwargs = len(spec.defaults or [])
			isflag = lambda x, y: '' if x.defaults[y] is False else '='

			func.args = spec.args[:(num_args - num_kwargs)]
			func.defaults = {spec.args[i - num_kwargs]: spec.defaults[i] for i in range(num_kwargs)}
			func.kwargs = [key.replace('_','-') + isflag(func, key) for key in func.defaults]

		if not func.name.startswith('_'):
			TASKS.append(func)

	return func
694850
function injectGlobals (funcs, task) {
  /**
   * Inject task
   */

  function inject (taskKey) {
    var taskName = task[taskKey]

    // Do not overwrite a function if already defined.
    // For example, console.log cannot be used as is, it must binded to console.
    if (typeof funcs[taskName] === 'function') return

    // Skip also reserved keywords.
    if (reservedKeys.indexOf(taskName) > -1) return

    var globalValue = walkGlobal(taskName)

    if (no(globalValue)) return

    if (typeof globalValue === 'function') {
      funcs[taskName] = globalValue
    } else {
      funcs[taskName] = function () {
        return globalValue
      }
    }
  }

  Object.keys(task)
    .forEach(inject)
}
1250424
function taskProcessor(params, isTX) {

            if (typeof params.cb !== 'function') {
                return $p.reject(new TypeError('Callback function is required.'));
            }

            if (params.options.reusable) {
                return config.$npm.task.callback(obj.ctx, obj, params.cb, config);
            }

            const taskCtx = ctx.clone(); // task context object;
            if (isTX) {
                taskCtx.txLevel = taskCtx.txLevel >= 0 ? (taskCtx.txLevel + 1) : 0;
            }
            taskCtx.inTransaction = taskCtx.txLevel >= 0;
            taskCtx.level = taskCtx.level >= 0 ? (taskCtx.level + 1) : 0;
            taskCtx.cb = params.cb; // callback function;
            taskCtx.mode = params.options.mode; // transaction mode;
            if (this !== obj) {
                taskCtx.context = this; // calling context object;
            }

            const tsk = new config.$npm.task.Task(taskCtx, params.options.tag, isTX, config);
            taskCtx.taskCtx = tsk.ctx;
            extend(taskCtx, tsk);

            if (taskCtx.db) {
                // reuse existing connection;
                npm.utils.addReadProp(tsk.ctx, 'useCount', taskCtx.db.useCount);
                return config.$npm.task.execute(taskCtx, tsk, isTX, config);
            }

            // connection required;
            return config.$npm.connect.pool(taskCtx, dbThis)
                .then(db => {
                    taskCtx.connect(db);
                    npm.utils.addReadProp(tsk.ctx, 'useCount', db.useCount);
                    return config.$npm.task.execute(taskCtx, tsk, isTX, config);
                })
                .then(data => {
                    taskCtx.disconnect();
                    return data;
                })
                .catch(error => {
                    taskCtx.disconnect();
                    return $p.reject(error);
                });
        }
383253
function ( taskName ) {
			var task = grunt.config.get( "bundles" )[taskName];

			var retVal = {};
			if ( task && task.aliases ) {
				var aliases = task.aliases;
				if ( !sys.isEmpty( aliases ) ) {
					grunt.verbose.writeln( "Adding aliases for " + taskName );
					if ( sys.isArray( aliases ) ) {
						sys.each( aliases, function ( map ) {
							map = map || {};

							if ( !sys.isString( map.dest ) ) {map.dest = map.cwd;}
							if ( !sys.isString( map.dest ) ) {return grunt.util.error( "dest or cwd is required" );}

							map.cwd = map.cwd || "";
							map.expand = map.expand !== false;
							var files = grunt.file.expand( map, map.src );
							sys.each( files, function ( item ) {
								var thisPath;
								if ( sys.isEmpty( map.dest ) ) {
									thisPath = item;
								} else {
									thisPath = path.join( map.dest, item );
								}

								var thisAlias = thisPath.replace( /\.[^/.]+$/, "" ).replace( /\\/g, "/" );

								retVal[thisAlias] = resolvePath( path.join( map.cwd, item ) );

							} );
						} );
					} else {
						sys.each( aliases, function ( item, key ) {
							retVal[key] = resolvePath( item );
						} );

					}
				}
			}
			return retVal;
		}
928722
function inject (taskKey) {
    var referenceName = null
    var referencedFunction = null
    var taskName = task[taskKey]

    /**
     * Inject reference.
     */

    function reference () {
      return referencedFunction
    }

    if (regexReference.test(taskName)) {
      referenceName = taskName.substring(1)

      if (typeof funcs[referenceName] === 'function') {
        referencedFunction = funcs[referenceName]
      } else {
        referencedFunction = walkGlobal(referenceName)
      }

      if (typeof referencedFunction === 'function') {
        funcs[taskName] = reference
      }
    }
  }
1052085
def synctasklet(func):
  
  taskletfunc = tasklet(func)  # wrap at declaration time.

  @utils.wrapping(func)
  def synctasklet_wrapper(*args, **kwds):
    # pylint: disable=invalid-name
    __ndb_debug__ = utils.func_info(func)
    return taskletfunc(*args, **kwds).get_result()
  return synctasklet_wrapper
664021
function inject (taskKey) {
    var funcName = task[taskKey]

    if (funcName === 'arguments') {
      funcs[funcName] = function getArguments () { return args }
    } else {
      var arg = regexArgument.exec(funcName)

      if (arg) {
        funcs[funcName] = getArgument.bind(null, arg[1])
      }
    }
  }
1004933
def add_task(self, fn, inputs=None, outputs=None):
        
        # self.tasks.append({'task': task, 'inputs': inputs, 'outputs': outputs})
        self.tasks.append(Task(fn, inputs, outputs))
        return self
1053940
def add_task(self, func, *args, **kargs):
        
        self.tasks.put((func, args, kargs))
861629
def task(func):
    
    def task_wrapper(*args, **kwargs):
        return spawn(func, *args, **kwargs)
    return task_wrapper
1295519
public static void convert(Task task, Function<Throwable, RuntimeException> function) {
        try {
            task.run();
        } catch (Throwable e) {
            throw function.apply(e);
        }
    }
150996
function fun (graph, additionalFunctions) {
  // First of all, check if graph is valid.
  try {
    validate(graph, additionalFunctions)
  } catch (err) {
    throw err
  }

  var func = graph.func || {}
  var pipe = graph.pipe
  var task = graph.task

  var cachedLevelOf = {}
  var computeLevelOf = level.bind(null, pipe, cachedLevelOf)
  var funcs = builtinFunctions

  // Inject compile-time builtin tasks.

  funcs['dflow.fun'] = fun
  funcs['dflow.isDflowFun'] = isDflowFun
  funcs['dflow.validate'] = validate

  injectAccessors(funcs, graph)
  injectAdditionalFunctions(funcs, additionalFunctions)
  injectDotOperators(funcs, task)
  injectGlobals(funcs, task)
  injectReferences(funcs, task)
  injectStrings(funcs, task)
  injectNumbers(funcs, task)
  evalTasks(funcs, task)

  /**
   * Compiles a sub graph.
   */

  function compileSubgraph (key) {
    var subGraph = graph.func[key]

    var funcName = '/' + key

    funcs[funcName] = fun(subGraph, additionalFunctions)
  }

  /**
   * Sorts tasks by their level.
   */

  function byLevel (a, b) {
    if (no(cachedLevelOf[a])) cachedLevelOf[a] = computeLevelOf(a)

    if (no(cachedLevelOf[b])) cachedLevelOf[b] = computeLevelOf(b)

    return cachedLevelOf[a] - cachedLevelOf[b]
  }

  /**
   * Ignores comments.
   */

  function comments (key) {
    return !regexComment.test(task[key])
  }

  // Compile each subgraph.
  Object.keys(func)
    .forEach(compileSubgraph)

  /**
   * Throw if a task is not compiled.
   */

  function checkTaskIsCompiled (taskKey) {
    var taskName = task[taskKey]

    // Ignore tasks injected at run time.
    if (reservedKeys.indexOf(taskName) > -1) return

    var msg = 'Task not compiled: ' + taskName + ' [' + taskKey + ']'

    // Check subgraphs.
    if (regexSubgraph.test(taskName)) {
      var subgraphKey = taskName.substring(1)

      if (no(graph.func[subgraphKey])) {
        var subgraphNotFound = new Error(msg)
        subgraphNotFound.taskKey = taskKey
        subgraphNotFound.taskName = taskName
        throw subgraphNotFound
      } else return
    }

    // Skip dflow DSL.
    if (isDflowDSL(taskName)) return

    // Skip globals.
    if (walkGlobal(taskName)) return

    if (no(funcs[taskName])) {
      var subgraphNotCompiled = new Error(msg)
      subgraphNotCompiled.taskKey = taskKey
      subgraphNotCompiled.taskName = taskName
      throw subgraphNotCompiled
    }
  }

  // Check if there is some missing task.
  Object.keys(task)
    .filter(comments)
    .forEach(checkTaskIsCompiled)

  /**
   * Here we are, this is the ❤ of dflow.
   */

  function dflowFun () {
    var gotReturn = false
    var returnValue
    var outs = {}

    // Inject run-time builtin tasks.

    funcs['this'] = function () { return dflowFun }
    funcs['this.graph'] = function () { return graph }
    injectArguments(funcs, task, arguments)

    /**
     * Execute task.
     */

    function run (taskKey) {
      var args = inputArgs(outs, pipe, taskKey)
      var taskName = task[taskKey]
      var f = funcs[taskName]

      // Behave like a JavaScript function:
      // if found a return, skip all other tasks.

      if (gotReturn) return

      if ((taskName === 'return') && (!gotReturn)) {
        returnValue = args[0]
        gotReturn = true
        return
      }

      // If task is not defined at run time, throw an error.

      if (no(f)) {
        var taskNotFound = new Error('Task not found: ' + taskName + ' [' + taskKey + '] ')
        taskNotFound.taskKey = taskKey
        taskNotFound.taskName = taskName
      }

      // Try to execute task.

      try {
        outs[taskKey] = f.apply(null, args)
      } catch (err) {
        // Enrich error with useful dflow task info.
        err.taskName = taskName
        err.taskKey = taskKey

        throw err
      }
    }

    // Run every graph task, sorted by level.

    Object.keys(task)
      .filter(comments)
      .sort(byLevel)
      .forEach(run)

    return returnValue
  }

  // Remember function was created from a dflow graph.

  dflowFun.graph = graph

  return dflowFun
}
765261
function binder(taskID) {
		expected++;
		return function(ret) {
			expected--;
			if(!returned && taskID !== 'false') {
				if		(typeof taskID == 'number') returned=[];
				else if (typeof taskID == 'string') returned={};
			};
			taskID !== false ? returned[taskID]=ret : returned = ret;
			// Timeout needed to increment expected, if next item exists.
			// If it run without timeout, expected always be 0 and only
			// the first function of the group will be executed.
			setTimeout(function(){if (! expected) runQueue();},1);
		}
	}
362963
function(task) {
            var f = task.task || this.defaultTask;

            Q(f.apply(task.context || this.defaultContext, task.args)).then(function() {
                task.result.resolve.apply(task.result, arguments);
            }, function() {
                task.result.reject.apply(task.result, arguments);
            }).fin(_.bind(this.startNext, this));
        }
512725
function evalTasks (funcs, task) {
  /**
  * Evaluate a single task and inject it.
  *
  * @param {String} taskKey
  */

  function inject (taskKey) {
    var taskName = task[taskKey]

    try {
      var e = eval(taskName) // eslint-disable-line

      if (typeof e === 'function') {
        funcs[taskName] = e
      } else {
        funcs[taskName] = function () { return e }
      }
    } catch (err) {
      var msg = 'Task not compiled: ' + taskName + ' [' + taskKey + ']' + err
      throw new Error(msg)
    }
  }

  Object.keys(task)
    .filter(reserved(task))
    .filter(dflowDSL(task))
    .filter(alreadyDefined(funcs, task))
    .forEach(inject)
}