activebridge 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5150c06f013c027ff680deee10287b3f8e0dc39042593cb926641efd4974a0e4
4
- data.tar.gz: 80b8f68037888ff78da09e720d6cdd43ba2aae8ddfdbdd2cb0809a6df6b52a53
3
+ metadata.gz: 16e6404432ed07b76f64563aa8d02f63c43657a24e5b76516968663f747ad3d8
4
+ data.tar.gz: 3e9b2bf0d8fd47f809510a04bc66057906a7e0bc07da3e2fc9b58913ff1566d3
5
5
  SHA512:
6
- metadata.gz: 6dada0c2383a6131bd8c56ff32b2f9fc485f365be46ab088777cf3f72736b44b8514bec75cbaa2f0f0ff43524ccbae4da9f393b0cf01d1273b52560a01723145
7
- data.tar.gz: d39c2f61bf1455acb5a1f1ef185b6dc940e539402afbf076e7107a07cc4c874b4863c40656df8330f623b3e3bc5b25656b462e60c8605e64f8809464d0029a50
6
+ metadata.gz: ce30d371d0c85f494766990d47504cb17d09bf74a26507c14d5acc0786563d4819422f799842be0a809fc8ec8326440b3ea11b4ba0e80523683ce43fc2c072b5
7
+ data.tar.gz: 754d69618667f96d0d69c5992972057b39f68c7516aba0e3ccc242446b2f04db25e9605ff4773523330b4a6de4028cdc47193fcb5f3183b06f7c38ad143a6cee
data/.standard.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  # For available configuration options, see:
2
2
  # https://github.com/testdouble/standard
3
3
  ruby_version: 2.6
4
+
5
+ ignore:
6
+ - "lib/active_bridge.rb"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activebridge (0.0.1)
4
+ activebridge (0.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,39 +1,6 @@
1
- # Activebridge
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activebridge`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
1
+ # ActiveBridge
10
2
 
11
3
  ```ruby
12
- gem 'activebridge'
4
+ require 'activebridge'
5
+ include ActiveBridge
13
6
  ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install activebridge
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activebridge.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -8,3 +8,9 @@ RSpec::Core::RakeTask.new(:spec)
8
8
  require "standard/rake"
9
9
 
10
10
  task default: %i[spec standard]
11
+
12
+ task "e2e" do
13
+ Dir.glob("e2e/*") do |path|
14
+ sh "ruby #{path}"
15
+ end
16
+ end
data/e2e/execute.rb ADDED
@@ -0,0 +1,19 @@
1
+ require_relative "../lib/active_bridge"
2
+
3
+ status, took, value = execute do
4
+ sleep 0.2
5
+ [1, 2, 3]
6
+ end
7
+
8
+ puts "status: #{status.inspect}"
9
+ puts "took: #{took}"
10
+ puts "value: #{value.inspect}"
11
+
12
+ status, took, value = execute timeout: 0.1 do
13
+ sleep 0.2
14
+ [1, 2, 3]
15
+ end
16
+
17
+ puts "status: #{status.inspect}"
18
+ puts "took: #{took}"
19
+ puts "value: #{value.inspect}"
data/e2e/throttle.rb ADDED
@@ -0,0 +1,11 @@
1
+ require_relative "../lib/active_bridge"
2
+
3
+ 3.times do
4
+ started_at = Time.now
5
+
6
+ sleep amount = rand
7
+ throttled = throttle started_at, 1
8
+
9
+ sum = amount + throttled
10
+ puts "amount: #{amount}, throttled: #{throttled}, sum: #{sum}"
11
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveBridge
4
+ def execute(opts = {}, &block)
5
+ queue = Queue.new
6
+ timeout_thr = if opts[:timeout]
7
+ Thread.new do
8
+ queue.push [:timeout, sleep(opts[:timeout])]
9
+ end
10
+ end
11
+ started_at = Time.now
12
+ main_thr = Thread.new do
13
+ queue.push [:ok, block.call]
14
+ end
15
+
16
+ op, value = queue.pop
17
+ took = Time.now - started_at
18
+
19
+ timeout_thr&.kill
20
+ main_thr.kill
21
+ main_thr.kill
22
+ main_thr.kill
23
+
24
+ case op
25
+ when :timeout
26
+ [:timeout, took, nil]
27
+ when :ok
28
+ [:ok, took, value]
29
+ else
30
+ raise "well, this is interesting"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveBridge
4
+ def throttle(started_at, max)
5
+ took = Time.now - started_at
6
+ remaining = max - took
7
+ sleep remaining if remaining > 0
8
+ remaining
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveBridge
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
data/lib/active_bridge.rb CHANGED
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "active_bridge/version"
4
+ require_relative "active_bridge/throttle"
5
+ require_relative "active_bridge/execute"
4
6
 
5
- module ActiveBridge
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
7
+ include ActiveBridge
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activebridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: activebridge
14
14
  email:
@@ -27,7 +27,11 @@ files:
27
27
  - README.md
28
28
  - Rakefile
29
29
  - activebridge.gemspec
30
+ - e2e/execute.rb
31
+ - e2e/throttle.rb
30
32
  - lib/active_bridge.rb
33
+ - lib/active_bridge/execute.rb
34
+ - lib/active_bridge/throttle.rb
31
35
  - lib/active_bridge/version.rb
32
36
  - sig/activebridge.rbs
33
37
  homepage: https://github.com/matti/activebridge