Skip to content

NameError: uninitialized constant inside Async::Task #172

@gdonald

Description

@gdonald

I don't seem to have scope for my ActiveRecord model inside an Async::Task.

For my model named F I get:

NameError: uninitialized constant F

My implementation:

Async do
  # Queue of up to 10 items:
  items = Async::LimitedQueue.new(10)

  # Five producers:
  5.times do
    Async do |task|
      # while true
      while F.unchecked.count.positive?
        # t = rand
        f = F.unchecked.first
        f.do_checking!
        t = check_f(f)

        task.sleep(t)
        items.enqueue(t)
      end
    end
  end

  # A single consumer:
  Async do |task|
    while item = items.dequeue
      puts "dequeue -> #{item}"
    end
  end
end

I also tried using ::F but got the same error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions