Class: Rufio::AsyncScannerPromise
- Inherits:
-
Object
- Object
- Rufio::AsyncScannerPromise
- Defined in:
- lib/rufio/async_scanner_promise.rb
Overview
Promise風インターフェースで非同期スキャンを扱うクラス
使用例:
scanner = NativeScannerRubyCore.new
AsyncScannerPromise.new(scanner)
.scan_async('/path')
.then { |entries| entries.select { |e| e[:type] == 'file' } }
.then { |files| files.map { |f| f[:name] } }
.wait
Instance Method Summary collapse
-
#initialize(scanner) ⇒ AsyncScannerPromise
constructor
A new instance of AsyncScannerPromise.
-
#scan_async(path) ⇒ AsyncScannerPromise
非同期スキャンを開始.
-
#scan_fast_async(path, max_entries) ⇒ AsyncScannerPromise
高速スキャンを開始(エントリ数制限付き).
-
#then {|result| ... } ⇒ AsyncScannerPromise
コールバックを登録.
-
#wait(timeout: nil) ⇒ Object
スキャン完了を待ち、コールバックを順次実行.
Constructor Details
#initialize(scanner) ⇒ AsyncScannerPromise
Returns a new instance of AsyncScannerPromise.
15 16 17 18 |
# File 'lib/rufio/async_scanner_promise.rb', line 15 def initialize(scanner) @scanner = scanner @callbacks = [] end |
Instance Method Details
#scan_async(path) ⇒ AsyncScannerPromise
非同期スキャンを開始
24 25 26 27 |
# File 'lib/rufio/async_scanner_promise.rb', line 24 def scan_async(path) @scanner.scan_async(path) self end |
#scan_fast_async(path, max_entries) ⇒ AsyncScannerPromise
高速スキャンを開始(エントリ数制限付き)
34 35 36 37 |
# File 'lib/rufio/async_scanner_promise.rb', line 34 def scan_fast_async(path, max_entries) @scanner.scan_fast_async(path, max_entries) self end |
#then {|result| ... } ⇒ AsyncScannerPromise
コールバックを登録
43 44 45 46 |
# File 'lib/rufio/async_scanner_promise.rb', line 43 def then(&block) @callbacks << block if block_given? self end |
#wait(timeout: nil) ⇒ Object
スキャン完了を待ち、コールバックを順次実行
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rufio/async_scanner_promise.rb', line 52 def wait(timeout: nil) result = @scanner.wait(timeout: timeout) # 登録されたコールバックを順次実行 @callbacks.each do |callback| result = callback.call(result) end result ensure # 完了後はスキャナーを自動的にクローズ @scanner.close end |