delayer-deferred 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b74d1715e4cbcfe9514171ebe201bde36bf00d8dcecef790ed4a29fd40449535
4
- data.tar.gz: 48353be255fdc9a97836aae40244e715b2b57c4e0c97d95bcfdda934b627b0f3
3
+ metadata.gz: 635fe49f73b6786a91d67fde17506967133e0f1c8489136e789d2f5394ffe69a
4
+ data.tar.gz: b05620a688dfc066237f3fb26e86ee50d3278125f5257e636f948a2f7bef4901
5
5
  SHA512:
6
- metadata.gz: 65b7ee78225e474f6cfbae098047098254e64dd3e009f9ad8158ce3d9e5a82da881d4069d1c5351a7c4fcb7228a5c14830fa96079cd5191853bcfb4692dc0e21
7
- data.tar.gz: 20167f6264beff6fa8926d90311fd595462cfb7810570e0af4c91edeeb7b4dc57157db405492a40599ed7c43572378310b6c6222ec8c70e5d67be38707e3361e
6
+ metadata.gz: 77596d4f0483b2305e5539c88de5f5f2bb493fcaf7b6c6877b4d16c4bb32a57d4e9bc70819535ecfbf800dd888400a4f05d145d3efdd1700dd2d7ac496ef1cc9
7
+ data.tar.gz: 8bda3e09f41a972c68ea752733e011071680818a2156ba4e4beb44416fb342fede1e910b22d20611208f637258cad9cb403c70bb73cfe21db90dcf1a96fee047
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 2.4.0'
22
22
 
23
- spec.add_dependency "delayer", ">= 1.0", "< 2.0"
23
+ spec.add_dependency "delayer", ">= 1.1.2", "< 2.0"
24
24
 
25
25
  spec.add_development_dependency "bundler"
26
26
  spec.add_development_dependency "rake", ">= 12.3.2"
@@ -64,5 +64,19 @@ module Delayer::Deferred
64
64
  raise ForeignCommandAborted.new("command aborted: #{args.join(' ')}", process: status) end
65
65
  }
66
66
  end
67
+
68
+ # _sec_ 秒後にsuccessとなるPromiseを返す
69
+ # ==== Args
70
+ # [sec] 待つ秒数
71
+ # ==== Return
72
+ # Deferred
73
+ def sleep(sec)
74
+ # pp [sec]
75
+ delayer.Promise.new(true).tap do |promise|
76
+ delayer.new(delay: sec) do
77
+ promise.call()
78
+ end
79
+ end
80
+ end
67
81
  end
68
82
  end
@@ -1,5 +1,5 @@
1
1
  module Delayer
2
2
  module Deferred
3
- VERSION = "2.1.3"
3
+ VERSION = "2.2.0"
4
4
  end
5
5
  end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'pry'
3
+ require_relative 'helper'
4
+
5
+ describe(Delayer::Deferred) do
6
+ include TestUtils
7
+
8
+ before do
9
+ @delayer = Delayer.generate_class
10
+ end
11
+ # delayer.new(delay: Time.new) { a << 0 }
12
+
13
+ it "Deferred.sleep returns promise when resolve after n minutes" do
14
+ lst = []
15
+ eval_all_events(@delayer) do
16
+ @delayer.Deferred.sleep(0.1).next do
17
+ lst << 1
18
+ end
19
+ @delayer.Deferred.next do
20
+ lst << 2
21
+ end
22
+ end
23
+ sleep 0.2
24
+ @delayer.run
25
+ #assert_equal false, failure
26
+ assert_equal [2, 1], lst, "Deferred did not executed."
27
+ end
28
+ end
@@ -1,7 +1,7 @@
1
1
  module TestUtils
2
- def eval_all_events(delayer=Delayer)
2
+ def eval_all_events(delayer=Delayer, &block)
3
3
  native = Thread.list
4
- result = yield if block_given?
4
+ result = block&.call()
5
5
  while not(delayer.empty? and (Thread.list - native).empty?)
6
6
  delayer.run
7
7
  Thread.pass
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayer-deferred
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiaki Asai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-12 00:00:00.000000000 Z
11
+ date: 2020-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: delayer
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 1.1.2
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '1.0'
29
+ version: 1.1.2
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.0'
@@ -187,6 +187,7 @@ files:
187
187
  - test/graph_test.rb
188
188
  - test/helper.rb
189
189
  - test/promise_test.rb
190
+ - test/sleep_test.rb
190
191
  - test/testutils.rb
191
192
  - test/thread_test.rb
192
193
  homepage: https://github.com/toshia/delayer-deferred
@@ -220,5 +221,6 @@ test_files:
220
221
  - test/graph_test.rb
221
222
  - test/helper.rb
222
223
  - test/promise_test.rb
224
+ - test/sleep_test.rb
223
225
  - test/testutils.rb
224
226
  - test/thread_test.rb