heartbleed 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 305567814526effc305093c6186f2589c3e768db9a4f63f12a999272ed23693f
4
+ data.tar.gz: 675a197d5672ba817c28ddd0e97c5d078485a5151c00a7ab52326853b6c7ec3f
5
+ SHA512:
6
+ metadata.gz: 18d354f412045bede7b0554d0d5230115e89df71b619b494e05ff50ee5b76827e44ae472a94606f50c2032e1a7ddbdbb23f4e977c3df00a4228fb647a9090117
7
+ data.tar.gz: d87ce952f978cdd4fafdb432a80f64ad388c6673e6c4c825e3e26d026098de1eefacef05ab0252563da0e0632743b4cd1971d4c0d0b7631aebff578dbdb4ba56
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2013 Michael Grosser <michael@grosser.it>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ class Heartbleed
3
+ class Missed < RuntimeError
4
+ end
5
+
6
+ def self.raise_when_missed(interval)
7
+ heartbeat = new(interval)
8
+ heartbeat.start
9
+
10
+ begin
11
+ yield heartbeat
12
+ ensure
13
+ heartbeat.stop
14
+ end
15
+ end
16
+
17
+ def initialize(interval)
18
+ @interval = interval
19
+ beat
20
+ end
21
+
22
+ def start
23
+ mainline = Thread.current
24
+
25
+ @thread = Thread.new do
26
+ loop do
27
+ pause = @check_at - now
28
+ if pause <= 0
29
+ mainline.raise Missed
30
+ break
31
+ end
32
+ sleep pause
33
+ end
34
+ end
35
+ end
36
+
37
+ def stop
38
+ @thread.kill
39
+ @thread.join
40
+ end
41
+
42
+ def beat
43
+ @check_at = now + @interval
44
+ end
45
+
46
+ private
47
+
48
+ def now
49
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ class Heartbleed
3
+ VERSION = "0.1.0"
4
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heartbleed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Grosser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: michael@grosser.it
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - MIT-LICENSE
20
+ - lib/heartbleed.rb
21
+ - lib/heartbleed/version.rb
22
+ homepage: https://github.com/grosser/heartbleed
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.3.0
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Tiny/Efficient/Simple library that stops your code when it gets stuck
45
+ test_files: []