[dry-effects] Trouble with using timeout effect

Hi, I’ve tried to wrap my head around dry-effects and algebraic effects in general. It’s really interesting, but I’ve struggled in running the first randomly taken example based on the docs. I’ve created a simple script to play around with the timeout effect, but I only get an unhandled effect error.

Could someone point me what I’m doing wrongly here? Thanks!

ruby typing.rb            
/Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/provider/class_interface.rb:44: warning: Passing the keyword argument as the last hash parameter is deprecated
/Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/providers/timeout.rb:9: warning: The called method `handle_method' is defined here
/Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-initializer-3.0.4/lib/dry/initializer/mixin/root.rb:7: warning: Passing the keyword argument as the last hash parameter is deprecated
(eval):2: warning: The called method `__dry_initializer_initialize__' is defined here
Traceback (most recent call last):
        14: from typing.rb:57:in `<main>'
        13: from typing.rb:41:in `call'
        12: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/provider/class_interface.rb:51:in `block (2 levels) in mixin'
        11: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:74:in `call'
        10: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/providers/timeout.rb:31:in `call'
         9: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:76:in `block in call'
         8: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/stack.rb:32:in `push'
         7: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:77:in `block (2 levels) in call'
         6: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:43:in `spawn_fiber'
         5: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:43:in `loop'
         4: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:46:in `block in spawn_fiber'
         3: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/stack.rb:24:in `call'
         2: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:47:in `block (2 levels) in spawn_fiber'
         1: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects.rb:37:in `yield'
/Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects.rb:37:in `yield': can't yield from root fiber (FiberError)
        7: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/frame.rb:39:in `block in spawn_fiber'
        6: from typing.rb:41:in `block in call'
        5: from typing.rb:17:in `call'
        4: from typing.rb:17:in `times'
        3: from typing.rb:18:in `block in call'
        2: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects/effects/timeout.rb:20:in `block (2 levels) in initialize'
        1: from /Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects.rb:36:in `yield'
/Users/sebastian/.rvm/gems/ruby-2.7.1/gems/dry-effects-0.1.5/lib/dry/effects.rb:48:in `rescue in yield': Effect #<Dry::Effects::Effects::Timeout::TimeoutEffect type=:timeout name=:timeout scope=:timeout> not handled. Effects must be wrapped with corresponding handlers (Dry::Effects::Errors::UnhandledEffectError)

Here is the script.

# frozen_string_literal: true

require 'io/console'

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'dry-effects'
end

module Typing
  class Application
    include Dry::Effects.Timeout(:timeout)

    def call
      1000000.times do
        timeout
        print 'a'
      end
    end
  end

  class WithTimeout
    include Dry::Effects::Handler.Timeout

    def call
      with_timeout(1.0) { @app.call }
    end

    private

    attr_reader :app

    def initialize(app)
      @app = app
    end
  end
end


app = Typing::Application.new
withtimeout = Typing::WithTimeout.new(app)
withtimeout.call

Oh, I’ve fixed it by adding :timeout identifier to the line including handler.

  class WithTimeout
    include Dry::Effects::Handler.Timeout(:timeout)