“So let's cut the bullshit. Reactive programming is programming with asynchronous data streams” - @andrestaltz- # The introduction to Reactive Programming you've been missing
“non-blocking communication allows recipients to only consume resources while active, leading to less system overhead” - reactivemanifesto- # reactivemanifesto.org
# github.com/klappradla/jruby_ratpack_examples/hello_world require 'java' require 'jruby/core_ext' require 'bundler/setup' Bundler.require java_import 'ratpack.server.RatpackServer' RatpackServer.start do |server| server.handlers do |chain| chain.get do |ctx| ctx.render('Hello World from Ratpack / JRuby') end end end
“A promise is a representation of a value which will become available later. Methods such as map(Function) […] allow a pipeline of “operations” to be specified, that the value will travel through as it becomes available.” -ratpack docs- # ratpack.io/manual/current/api/ratpack/exec/Promise.html
# ratpack.io/manual/current/async.html#performing_blocking_operations_eg_io java_import 'ratpack.server.RatpackServer' java_import 'ratpack.exec.Blocking' require 'json' RatpackServer.start do |server| server.handlers do |chain| chain.get('music') do |ctx| Blocking .get { DB[:albums].all } .then { |data| ctx.render(JSON.dump(data))} end end end
RatpackServer.start do |server| server.handlers do |chain| chain.get('music') do |ctx| Blocking .get { DB[:albums].all } .then { |data| ctx.render(JSON.dump(data))} end end end
RatpackServer.start do |server| server.handlers do |chain| chain.get('music') do |ctx| Blocking .get { DB[:albums].all } .map { |data| JSON.dump(data) } .then { |data| ctx.render(data)} end end end
class Server def self.run RatpackServer.start do |server| server.handlers do |chain| chain.all(RequestLogger.ncsa) chain.get('music', Handler::Music) chain.get('planets', Handler::Planets) chain.all(Handler::NotFound) end end end end # github.com/klappradla/jruby_ratpack_examples/http_example
# github.com/klappradla/jruby_ratpack_examples/http_example module Handler class Base def self.handle(ctx) new(ctx).handle end def initialize(ctx) @ctx = ctx end attr_reader :ctx def handle raise NotImplementedError end end end