~singpolyma/em_fiberscheduler

8f7697063df25cd3dc71f185192db62cbae302f3 — Stephen Paul Weber 4 months ago 22853f2
Fix style cops
4 files changed, 161 insertions(+), 26 deletions(-)

A .rubocop.yml
M Gemfile
R lib/{em-fiberscheduler.rb => em_fiberscheduler.rb}
M spec/em_fiberscheduler_spec.rb
A .rubocop.yml => .rubocop.yml +132 -0
@@ 0,0 1,132 @@
AllCops:
  TargetRubyVersion: 2.5
  NewCops: enable

Metrics/ClassLength:
  CountAsOne:
    - heredoc
  Exclude:
    - test/*

Metrics/MethodLength:
  Exclude:
    - test/*

Metrics/BlockLength:
  ExcludedMethods:
    - route
    - "on"
  Exclude:
    - test/*

Metrics/AbcSize:
  Exclude:
    - test/*

Metrics/ParameterLists:
  Max: 6

Naming/MethodParameterName:
  AllowNamesEndingInNumbers: false
  AllowedNames:
    - m
    - e
    - q
    - s
    - k
    - v
    - ex
    - tx
    - id
    - iq
    - db
    - to

Layout/IndentationStyle:
  Enabled: false
  EnforcedStyle: tabs
  IndentationWidth: 2

Layout/IndentationWidth:
  Width: 1 # one tab

Layout/LineLength:
  Max: 80
  Exclude:
    - Gemfile

Layout/SpaceAroundEqualsInParameterDefault:
  EnforcedStyle: no_space

Layout/AccessModifierIndentation:
  EnforcedStyle: outdent

Layout/FirstParameterIndentation:
  EnforcedStyle: consistent

Style/AccessModifierDeclarations:
  Enabled: false

Style/StringLiterals:
  EnforcedStyle: double_quotes

Style/NumericLiterals:
  Enabled: false

Style/SymbolArray:
  EnforcedStyle: brackets

Style/WordArray:
  EnforcedStyle: brackets

Style/Documentation:
  Enabled: false

Style/DoubleNegation:
  EnforcedStyle: allowed_in_returns
  Enabled: false

Style/PerlBackrefs:
  Enabled: false

Style/SpecialGlobalVars:
  EnforcedStyle: use_perl_names

Style/RegexpLiteral:
  EnforcedStyle: slashes
  AllowInnerSlashes: true

Lint/OutOfRangeRegexpRef:
  Enabled: false

Lint/MissingSuper:
  Enabled: false

Style/BlockDelimiters:
  EnforcedStyle: semantic
  AllowBracesOnProceduralOneLiners: true
  ProceduralMethods:
    - execute_command
    - new

Style/MultilineBlockChain:
  Enabled: false

Layout/FirstArgumentIndentation:
  EnforcedStyle: consistent

Layout/FirstArrayElementIndentation:
  EnforcedStyle: consistent

Style/FormatString:
  EnforcedStyle: percent

Style/FormatStringToken:
  EnforcedStyle: unannotated

Style/FrozenStringLiteralComment:
  Exclude:
    - forms/**/*.rb

Naming/AccessorMethodName:
  Enabled: false

M Gemfile => Gemfile +5 -2
@@ 2,6 2,9 @@

source "https://rubygems.org"

gem "fiber_scheduler_spec"
gem "eventmachine"
gem "rspec"

group(:test) do
	gem "fiber_scheduler_spec"
	gem "rspec"
end

R lib/em-fiberscheduler.rb => lib/em_fiberscheduler.rb +23 -23
@@ 17,7 17,7 @@ module EventMachine

		def tick
			EM.next_tick do
				if @count > 0
				if @count.positive?
					tick
				else
					EM.stop


@@ 48,31 48,31 @@ module EventMachine
			Fiber.yield
		end

		def block(blocker, timeout=nil)
		def block(_, timeout=nil)
			if timeout
				fiber = Fiber.current
				@timeouts[fiber] = EM.add_timer(timeout) do
				@timeouts[fiber] = EM.add_timer(timeout) {
					@timeouts.delte(fiber)
					fiber.resume
				end
				}
			end
			Fiber.yield
		end

		def unblock(blocker, fiber)
		def unblock(_, fiber)
			timeout = @timeouts.delete(fiber)
			EM.cancel_timer(timeout) if timeout
			EM.next_tick { fiber.resume }
		end

		def io_wait(io, events, timeout=nil)
		def io_wait(io_or_fd, events, timeout=nil)
			fiber = Fiber.current
			EM.schedule do
				conn = EM.watch(io, IOWait)
				conn = EM.watch(io_or_fd, IOWait)
				conn.fiber = fiber
				conn.events = events & ~IO::PRIORITY
				conn.notify_readable = (events & IO::READABLE) > 0
				conn.notify_writable = (events & IO::WRITABLE) > 0
				conn.notify_readable = (events & IO::READABLE).positive?
				conn.notify_writable = (events & IO::WRITABLE).positive?

				if timeout
					EM.add_timer(timeout) do


@@ 114,9 114,9 @@ module EventMachine
			timer = nil
			fiber = Fiber.current
			EM.schedule do
				timer = EM.add_timer(duration) do
				timer = EM.add_timer(duration) {
					fiber.raise(exception_class, *exception_arguments)
				end
				}
			end
			block.call
		ensure


@@ 146,24 146,24 @@ module EventMachine
			attr_writer :fiber, :events

			def notify_readable
				if (@events & IO::READABLE) > 0
					@events &= ~IO::READABLE
					check
				end
				return unless (@events & IO::READABLE).positive?

				@events &= ~IO::READABLE
				check
			end

			def notify_writeable
				if (@events & IO::WRITEABLE) > 0
					@events &= ~IO::WRITEABLE
					check
				end
				return unless (@events & IO::WRITEABLE).positive?

				@events &= ~IO::WRITEABLE
				check
			end

			def check
				if @events.zero?
					EM.next_tick { @fiber.resume }
					detach
				end
				return unless @events.zero?

				EM.next_tick { @fiber.resume }
				detach
			end
		end
	end

M spec/em_fiberscheduler_spec.rb => spec/em_fiberscheduler_spec.rb +1 -1
@@ 2,7 2,7 @@

require "fiber_scheduler_spec"

require_relative "../lib/em-fiberscheduler"
require_relative "../lib/em_fiberscheduler"

RSpec.describe EM::FiberScheduler do
	include_examples FiberSchedulerSpec