Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move server side after and every methods to include module #350

Closed
catmando opened this issue Feb 14, 2021 · 1 comment
Closed

Move server side after and every methods to include module #350

catmando opened this issue Feb 14, 2021 · 1 comment
Labels
compatibility compatibility with dependencies such as Rails, Opal, React, etc. NOT FUNCTIONAL COMPATIBILITY

Comments

@catmando
Copy link
Contributor

Currently after and every methods are added to the Kernel module server side, so that Isomorphic Operations can use these methods uniformly on the server and client.

The problem is other gems tend to also add these methods (especially after) to the kernel.

So rather than add them to the kernel we should now add them to a module (Hyperstack::AsyncSleep as both instance and class methods.

Then you can include them in Operation classes (or elsewhere) as needed.

Also making them class level methods on both the server and client, you can say Hyperstack::AsyncSleep.after or .every any place without doing the include.

This will be a breaking change, but the work around is to either update the classes that are using after or every on the server to include AsyncSleep, or it could be done globally (i.e. include it into Object.)

module Hyperstack
  module AsyncSleep
    if RUBY_ENGINE == 'opal'
      def self.every(*args, &block)
        every(*args, &block)
      end

      def self.after(*args, &block)
        after(*args, &block)
      end
    else
      extend self

      def every(time, &block)
        Thread.new { loop { sleep time; block.call } }
      end

      def after(time, &block)
        Thread.new { sleep time; block.call }
      end
    end
  end
end
@catmando catmando added the compatibility compatibility with dependencies such as Rails, Opal, React, etc. NOT FUNCTIONAL COMPATIBILITY label Feb 14, 2021
@catmando
Copy link
Contributor Author

catmando commented Apr 5, 2021

closed in alpha1.6

@catmando catmando closed this as completed Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility compatibility with dependencies such as Rails, Opal, React, etc. NOT FUNCTIONAL COMPATIBILITY
Projects
None yet
Development

No branches or pull requests

1 participant