bloom-lang / bud

Prototype Bud runtime (Bloom Under Development)
http://bloom-lang.net
Other
854 stars 60 forks source link

EventMachine not started for Bud#tick() #237

Closed michaelficarra closed 12 years ago

michaelficarra commented 12 years ago

The following code produces the error ./bud/collections.rb:736:in flush': undefined methodsend_datagram' for nil:NilClass (NoMethodError).

require 'bud'

class TestClass
    include Bud

    state do
        loopback :lb, [:a] => []
        table :t, [:a] => []
        table :ft, [:a] => []
    end

    bootstrap do
        t <+- [["initial"], ["values"]]
        ft <+- [["additional"], ["values"]]
    end

    bloom :useLoopback do
        lb <~ ft
        t <+- lb
        stdio <~ t.inspected
    end
end

o = TestClass.new
o.tick
o.tick

I suspect it is related to the loopback because I don't receive the error whenever pieces that interact with the loopback channel are commented out.

edit: simplified example

neilconway commented 12 years ago

The issue here is that EventMachine is not started when you interact with Bud via the tick method. Hence, you can't use any Bud features that depend on EventMachine (including channels, loopbacks, and periodics).

It would be possible to fix this: EM would be unconditionally started, but any EM-generated events would be buffered/queued until the next call to tick is received. Sort of weird semantics, but it would make the class of programs that work via tick a lot closer to the programs that can be run via run_bg or run_fg.

jhellerstein commented 12 years ago

Addressed via a more informative error in commit 0e18483b0d85a2ee1e55

neilconway commented 12 years ago

A better error message is helpful, but IMHO the right long-term fix is to start EM when using single-stepped mode.

michaelficarra commented 12 years ago

I agree with @neilconway. Great short term fix, but I would really expect to be able to step through a program like the one above.

neilconway commented 12 years ago

This is fixed in 4ef34ee6c4cfd4573ff3.