# File lib/core/container.rb, line 55
    def initialize(*args)
      @handler, @id = nil
      case args.size
      when 2 then @handler, @id = args
      when 1 then
        @id = String.try_convert(args[0]) || (args[0].to_s if args[0].is_a? Symbol)
        @handler = args[0] unless @id
      when 0 then
      else raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0..2"
      end
      # Use an empty messaging adapter to give default behaviour if there's no global handler.
      @adapter = Handler::Adapter.adapt(@handler) || Handler::MessagingAdapter.new(nil)
      @id = (@id || SecureRandom.uuid).freeze

      # Threading and implementation notes: see comment on #run_one
      @work = Queue.new
      @work << :start
      @work << :select
      @wake = SelectWaker.new   # Wakes #run thread in IO.select
      @auto_stop = true         # Stop when @active drops to 0
      @work_queue = WorkQueue.new(self)  # work scheduled by other threads for :select context

      # Following instance variables protected by lock
      @lock = Mutex.new
      @active = 0               # All active tasks, in @selectable, @work or being processed
      @selectable = Set.new     # Tasks ready to block in IO.select
      @running = 0              # Count of #run threads
      @stopped = false          # #stop called
      @stop_err = nil           # Optional error to pass to tasks, from #stop
      @panic = nil              # Exception caught in a run thread, to be raised by all run threads
    end