{"record":{"id":"5c21a682cc13b84c","repo":"ruby-concurrency/concurrent-ruby","slug":"no-block-given-5c21a6","errorCode":null,"errorMessage":"no block given","messagePattern":"no block given","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/concurrent-ruby/concurrent/delay.rb","lineNumber":63,"sourceCode":"    include Concern::Obligation\n\n    # NOTE: Because the global thread pools are lazy-loaded with these objects\n    # there is a performance hit every time we post a new task to one of these\n    # thread pools. Subsequently it is critical that `Delay` perform as fast\n    # as possible post-completion. This class has been highly optimized using\n    # the benchmark script `examples/lazy_and_delay.rb`. Do NOT attempt to\n    # DRY-up this class or perform other refactoring with running the\n    # benchmarks and ensuring that performance is not negatively impacted.\n\n    # Create a new `Delay` in the `:pending` state.\n    #\n    # @!macro executor_and_deref_options\n    #\n    # @yield the delayed operation to perform\n    #\n    # @raise [ArgumentError] if no block is given\n    def initialize(opts = {}, &block)\n      raise ArgumentError.new('no block given') unless block_given?\n      super(&nil)\n      synchronize { ns_initialize(opts, &block) }\n    end\n\n    # Return the value this object represents after applying the options\n    # specified by the `#set_deref_options` method. If the delayed operation\n    # raised an exception this method will return nil. The exception object\n    # can be accessed via the `#reason` method.\n    #\n    # @param [Numeric] timeout the maximum number of seconds to wait\n    # @return [Object] the current value of the object\n    #\n    # @!macro delay_note_regarding_blocking\n    def value(timeout = nil)\n      if @executor # TODO (pitr 12-Sep-2015): broken unsafe read?\n        super\n      else\n        # this function has been optimized for performance and","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/ruby-concurrency/concurrent-ruby/blob/0b88d5ff75f69b3740c8f0868e76f833cb2fd45d/lib/concurrent-ruby/concurrent/delay.rb#L45-L81","documentation":"Concurrent::Delay defers a computation until #value is first called; the block given to new IS that computation, so it is mandatory. initialize raises ArgumentError('no block given') when the Delay is constructed without one, because a Delay with nothing to compute is meaningless.","triggerScenarios":"Concurrent::Delay.new with no block at all; Concurrent::Delay.new(timeout: 5) passing only options; passing the task as a positional argument (Concurrent::Delay.new(my_proc)) instead of Concurrent::Delay.new(&my_proc).","commonSituations":"Factory methods build a Delay from a stored proc and forget the &; the chosen task is conditionally nil; refactoring an eager call into lazy evaluation and dropping the block in the process.","solutions":["Pass the computation as a block: Concurrent::Delay.new { expensive_call }","Pass a stored callable with &: Concurrent::Delay.new(&task)","In factories, fail fast with raise unless task.respond_to?(:call) before constructing"],"exampleFix":"# before\ndelay = Concurrent::Delay.new(load_config)\n# after\ndelay = Concurrent::Delay.new { load_config }","handlingStrategy":"validation","validationCode":"raise ArgumentError, 'task must respond to #call' unless task.respond_to?(:call)\nConcurrent::Delay.new(&task)","typeGuard":null,"tryCatchPattern":"begin\n  Concurrent::Delay.new { compute }\nrescue ArgumentError => e\n  raise unless e.message == 'no block given'\n  Concurrent::Delay.new { default_value }\nend","preventionTips":["Construct Delay with a literal block whenever possible","Route variable callables through &task","In factories, reject non-callable tasks before reaching Delay.new"],"tags":["ruby","concurrency","delay","lazy-evaluation","argument-error","missing-block"],"backgroundTag":"missing-block-argument","analyzedSha":"0b88d5ff75f69b3740c8f0868e76f833cb2fd45d","analyzedAt":"2026-08-21T20:12:56.291Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}