Skip to content

Commit

Permalink
Add Telebugs::Promise and make Telebugs.notify return it
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Jun 6, 2024
1 parent 492bbe2 commit 166a8e2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/telebugs.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

require "concurrent"

require_relative "telebugs/version"
require_relative "telebugs/config"
require_relative "telebugs/promise"

module Telebugs
# The general error that this library uses when it wants to raise.
Expand All @@ -13,7 +16,7 @@ def configure
end

def notify(error:)
Concurrent::Promises.future do
Telebugs::Promise.new(error) do
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/telebugs/promise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module Telebugs
# Wraps Concurrent::Promise to provide a consistent API for promises that we
# can control.
class Promise
def initialize(*, &)
@future = Concurrent::Promises.future(*, &)
end

def value
@future.value
end
end
end
11 changes: 11 additions & 0 deletions test/test_promise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require "test_helper"

class TestPromise < Minitest::Test
def test_future_value
promise = Telebugs::Promise.new { 1 + 1 }

assert_equal 2, promise.value
end
end
2 changes: 1 addition & 1 deletion test/test_telebugs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def test_configure_configures_project_key
def test_notify_returns_a_future
future = Telebugs.notify(error: StandardError.new)

assert_instance_of Concurrent::Promises::Future, future
assert_instance_of Telebugs::Promise, future
end
end

0 comments on commit 166a8e2

Please sign in to comment.