[jruby-user] Eliminate Startup Delay ?

Robin McKay <[email protected]>
Newsgroups gmane.comp.lang.jruby.user
Message-ID <[email protected]>
I have been very tempted recently to give up JRuby in favour of Python.
Part of the reason is that I have been dabbling with Arduinos and the
Arduino community is more likely to be familiar with Python. And the
other part is the JRuby startup delay which is painfully obvious after
using Python for an hour.

Then it occurred to me that the startup delay could be avoided by
preventing JRuby from exiting when a program finished.

This short code is a first crude attempt to achieve that and it seems to
work. Indeed it runs the short test program so fast that I lose track of
whether I have pressed return. And it seems to catch load errors, syntax
errors, runtime errors and java errors (in a much larger program that I
tried).

I have little doubt that a more experienced JRuby programmer will see
scope for many improvements.

It would be nice if every possible exception could be trapped with a
single RESCUE clause - but I don't know how to do that.

==========

ScriptRunner.rb

[code]
def runScript
    begin
          # load is used because require would only load the script once
        load $jscriptName
          # it is assumed that the script contains a method called
scriptStart
        scriptStart
    rescue ScriptError       # catches load and syntax errors
        puts "SCRIPT ERROR A"
        puts $!
    rescue NativeException   # catches Java errors
        puts "SCRIPT ERROR B"
        puts $!
    rescue                     # catches runtime errors
        puts "SCRIPT ERROR C"
        puts $!
    end
end

puts
puts "Starting ScriptRunner"

$jscriptName = "./test.rb"

while true
  puts
  puts "Press Return"
  xxx = gets
  runScript
  puts "Done"
end
[/code]

=============

test.rb

[code]
def scriptStart
  puts "Hey - here is testing"
  xxx = 8 / 1
  puts xxx
end
[/code]

-- 
Posted via http://www.ruby-forum.com/.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.