Skip to content

Commit

Permalink
wait implementation complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuga-cb committed Apr 15, 2024
1 parent c341f14 commit 6ed8212
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/coinbase/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,24 @@ def status
end
end

# Waits until the Transfer is completed or failed by polling the Network at the given interval.
# @param interval_seconds [Integer] The interval at which to poll the Network, in seconds
# @param timeout_seconds [Integer] The maximum amount of time to wait for the Transfer to complete, in seconds
# @return [Transfer] The completed Transfer object
def wait!(interval_seconds = 0.2, timeout_seconds = 10)
start_time = Time.now

loop do
return self if status == Status::COMPLETE || status == Status::FAILED

raise Timeout::Error, 'Transfer timed out' if Time.now - start_time > timeout_seconds

sleep interval_seconds
end

self
end

# Returns the transaction hash of the Transfer, or nil if not yet available.
# @return [String] The transaction hash
def transaction_hash
Expand Down

0 comments on commit 6ed8212

Please sign in to comment.