code: def executor(arg: Union[Executor, str, Callable] = None):
      
      def outer_wrapper(func: Callable):
          @wraps(func)
          def inner_wrapper(*args, **kwargs):
              try:
                  ctx = next(arg for arg in args[:2] if isinstance(arg, Context))
              except StopIteration:
                  raise RuntimeError('the first positional argument to {}() has to be a Context '
                                     'instance'.format(callable_name(func))) from None
  
              executor = ctx.require_resource(Executor, resource_name)
              return asyncio_extras.call_in_executor(func, *args, executor=executor, **kwargs)
  
          return inner_wrapper
  
      if isinstance(arg, str):
          resource_name = arg
          return outer_wrapper
  
      return asyncio_extras.threadpool(arg)
docs: Decorate a function so that it runs in an :class:`~concurrent.futures.Executor`.
  
      If a resource name is given, the first argument must be a :class:`~.Context`.
  
      Usage::
  
          @executor
          def should_run_in_executor():
              ...
  
      With a resource name::
  
          @executor('resourcename')
          def should_run_in_executor(ctx):
              ...
  
      :param arg: a callable to decorate, an :class:`~concurrent.futures.Executor` instance, the
          resource name of one or ``None`` to use the event loop's default executor
      :return: the wrapped function