Class: Rufio::AsyncScannerFiberWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rufio/async_scanner_fiber.rb

Overview

Fiber(Asyncライブラリ)統合用ラッパークラス

Asyncライブラリと統合し、ノンブロッキングで非同期スキャンを実行します。

使用例:

Async do
  scanner = NativeScannerRubyCore.new
  wrapper = AsyncScannerFiberWrapper.new(scanner)
  entries = wrapper.scan_async('/path')
  puts "Found #{entries.length} entries"
end

Instance Method Summary collapse

Constructor Details

#initialize(scanner) ⇒ AsyncScannerFiberWrapper

Returns a new instance of AsyncScannerFiberWrapper.



24
25
26
# File 'lib/rufio/async_scanner_fiber.rb', line 24

def initialize(scanner)
  @scanner = scanner
end

Instance Method Details

#cancelObject

スキャンをキャンセル



70
71
72
# File 'lib/rufio/async_scanner_fiber.rb', line 70

def cancel
  @scanner.cancel
end

#get_progressHash

進捗を取得

Returns:

  • (Hash)

    進捗情報 total:



84
85
86
# File 'lib/rufio/async_scanner_fiber.rb', line 84

def get_progress
  @scanner.get_progress
end

#get_stateSymbol

状態を取得

Returns:

  • (Symbol)

    現在の状態



77
78
79
# File 'lib/rufio/async_scanner_fiber.rb', line 77

def get_state
  @scanner.get_state
end

#scan_async(path, timeout: nil) ⇒ Array<Hash>

非同期スキャンを開始し、Fiberで完了を待つ

Parameters:

  • path (String)

    スキャンするディレクトリのパス

  • timeout (Integer, nil) (defaults to: nil)

    タイムアウト秒数(オプション)

Returns:

  • (Array<Hash>)

    スキャン結果



33
34
35
36
37
38
39
# File 'lib/rufio/async_scanner_fiber.rb', line 33

def scan_async(path, timeout: nil)
  # スキャンを開始
  @scanner.scan_async(path)

  # Fiberでポーリング
  poll_until_complete(timeout: timeout)
end

#scan_async_with_progress(path, timeout: nil) {|current, total| ... } ⇒ Array<Hash>

進捗報告付きスキャン

Parameters:

  • path (String)

    スキャンするディレクトリのパス

  • timeout (Integer, nil) (defaults to: nil)

    タイムアウト秒数(オプション)

Yields:

  • (current, total)

    進捗情報を受け取るブロック

Returns:

  • (Array<Hash>)

    スキャン結果



61
62
63
64
65
66
67
# File 'lib/rufio/async_scanner_fiber.rb', line 61

def scan_async_with_progress(path, timeout: nil, &block)
  # スキャンを開始
  @scanner.scan_async(path)

  # 進捗付きでポーリング
  poll_until_complete_with_progress(timeout: timeout, &block)
end

#scan_fast_async(path, max_entries, timeout: nil) ⇒ Array<Hash>

高速スキャン(エントリ数制限付き)

Parameters:

  • path (String)

    スキャンするディレクトリのパス

  • max_entries (Integer)

    最大エントリ数

  • timeout (Integer, nil) (defaults to: nil)

    タイムアウト秒数(オプション)

Returns:

  • (Array<Hash>)

    スキャン結果



47
48
49
50
51
52
53
# File 'lib/rufio/async_scanner_fiber.rb', line 47

def scan_fast_async(path, max_entries, timeout: nil)
  # スキャンを開始
  @scanner.scan_fast_async(path, max_entries)

  # Fiberでポーリング
  poll_until_complete(timeout: timeout)
end