Skip to content
This repository
tag: r0.4.0
Fetching contributors…

Cannot retrieve contributors at this time

file 30 lines (22 sloc) 0.601 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

# Computes Pascals triangle using procrastinate. This is mainly a stress test
# for result handling code and is NOT how I would parallelize this task!

$:.unshift File.dirname(__FILE__) + '/../lib'

require 'procrastinate'
require 'procrastinate/implicit'
include Procrastinate

V = Struct.new(:value) do
  def ready?; true; end
end

current = [
  V.new(1),
  V.new(1)
]

loop do
  last = current

  puts last.map { |e| sprintf("%3d", e.value) }.join(' ')
  
  current = [V.new(1)] +
    last.each_cons(2).map { |l,r|
      Procrastinate.schedule { l.value + r.value }
    } +
    [V.new(1)]
end
Something went wrong with that request. Please try again.