Class: SassListen::Event::Loop

Inherits:
Object
  • Object
show all
Defined in:
lib/sass-listen/event/loop.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Loop

Returns a new instance of Loop.


14
15
16
17
18
19
# File 'lib/sass-listen/event/loop.rb', line 14

def initialize(config)
  @config = config
  @wait_thread = nil
  @state = :paused
  @reasons = ::Queue.new
end

Instance Method Details

#pauseObject


55
56
57
58
# File 'lib/sass-listen/event/loop.rb', line 55

def pause
  # TODO: works?
  # fail NotImplementedError
end

#paused?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/sass-listen/event/loop.rb', line 28

def paused?
  wait_thread && state == :paused
end

#processing?Boolean

Returns:

  • (Boolean)

32
33
34
35
36
# File 'lib/sass-listen/event/loop.rb', line 32

def processing?
  return false if stopped?
  return false if paused?
  state == :processing
end

#resumeObject


49
50
51
52
53
# File 'lib/sass-listen/event/loop.rb', line 49

def resume
  fail Error::NotStarted if stopped?
  return unless wait_thread
  _wakeup(:resume)
end

#setupObject


38
39
40
41
42
43
44
45
46
47
# File 'lib/sass-listen/event/loop.rb', line 38

def setup
  # TODO: use a Fiber instead?
  q = ::Queue.new
  @wait_thread = Internals::ThreadPool.add do
    _wait_for_changes(q, config)
  end

  SassListen::Logger.debug('Waiting for processing to start...')
  Timeout.timeout(5) { q.pop }
end

#stopped?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'lib/sass-listen/event/loop.rb', line 69

def stopped?
  !wait_thread
end

#teardownObject


60
61
62
63
64
65
66
67
# File 'lib/sass-listen/event/loop.rb', line 60

def teardown
  return unless wait_thread
  if wait_thread.alive?
    _wakeup(:teardown)
    wait_thread.join
  end
  @wait_thread = nil
end

#wakeup_on_eventObject


21
22
23
24
25
26
# File 'lib/sass-listen/event/loop.rb', line 21

def wakeup_on_event
  return if stopped?
  return unless processing?
  return unless wait_thread.alive?
  _wakeup(:event)
end