opal-async 1.3.0 → 1.4.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: cc5f4a757a39dabc8a7bc7efcb87631a7dd6809f0fd7da29b5b40ec23d436ea8
4
- data.tar.gz: b7c60f66044d9e0f49c2b0a49c18046bccfbd89364fbbdb18d62323cf5351991
3
+ metadata.gz: bcf44d0cb1a3c702b3c60521a2e173b7a3824fd8a37e80cd0fb18d5c4e0ffc2c
4
+ data.tar.gz: 28e4364132c94e690752669a3211796ec2b3423314a0db4892348d92fb0beb46
5
5
  SHA512:
6
- metadata.gz: bc8669beff060d5f91ffad0b6f1ee68d4708124bb5be87d6759eb67ee7c84211c9a6c6a624a73c1eca170ccb305817d13f6472c9c9986c5488b4afbf918929c1
7
- data.tar.gz: cf3fe071bb8e549e76e447a5bfd1e28afceb6385a6f005dbef96a8a2b0c77596fbcbeeb05e9901933f151da36d307353dc4c8c13f02fedb39302f2015a2b6d35
6
+ metadata.gz: 695a85e00e549b7616d7bf120e8651d574c8d42cf58e4483fd7e0a7a36581942836457ad2bdb08a03232217f7bb92434a6fa75cbac217f5498e545186ae66430
7
+ data.tar.gz: e4a46e19095d1017f93574d52f40a47ff5dfd85b290ce0acb5a885e2500eec44813acdb2f3ea683ef6813711e0f8ccbb4c5beaae0969e3a908e0cb7bd51cf1ab
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.4.0
4
+
5
+ - Drop `Array#cycle` and `Array#each` overrides and re-implement as `Array#async_cycle` and `Array#async_each`
6
+ - Asynchronous `Kernel#async_loop` alternative to `Kernel#loop`
7
+
3
8
  ## 1.3.0
4
9
 
5
10
  - Asynchronous `Array#each` method that is web browser event loop friendly
data/README.md CHANGED
@@ -185,9 +185,9 @@ end
185
185
 
186
186
  #### Array
187
187
 
188
- The follow `Array` methods have been amended to work asynchronously via `Async::Task` when triggered inside another `Async::Task` (auto-detects it):
189
- - `Array#cycle`
190
- - `Array#each`
188
+ The follow `Array` methods have been added to work asynchronously via `Async::Task`:
189
+ - `Array#async_cycle`
190
+ - `Array#async_each`
191
191
 
192
192
  This makes them not block the web browser event loop, thus allowing other tasks to update the DOM unhindered while running.
193
193
 
@@ -197,12 +197,34 @@ Example:
197
197
  require 'async/ext/array' # not needed if you called `require 'async/ext'`
198
198
 
199
199
  Async::Task.new do
200
- [1,2,3,4].cycle do |n|
200
+ [1,2,3,4].async_cycle do |n|
201
201
  puts n
202
202
  Async::Task.new do
203
- # make a DOM update
203
+ # make a DOM update that is not blocked
204
204
  end
205
- sleep(1) # this does not block the event loop since it is transparently happening inside an Async::Task
205
+ sleep(1)
206
+ end
207
+ end
208
+ ```
209
+
210
+ #### Kernel
211
+
212
+ The follow `Kernel` method has been added to work asynchronously via `Async::Task`:
213
+ - `Array#async_loop`
214
+
215
+ This makes it not block the web browser event loop, thus allowing other tasks to update the DOM unhindered while running.
216
+
217
+ Example:
218
+
219
+ ```ruby
220
+ require 'async/ext/kernel' # not needed if you called `require 'async/ext'`
221
+
222
+ Async::Task.new do
223
+ async_loop do
224
+ Async::Task.new do
225
+ # make a DOM update that is not blocked
226
+ end
227
+ sleep(1)
206
228
  end
207
229
  end
208
230
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
data/opal/async/ext.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'async/ext/thread'
2
2
  require 'async/ext/array'
3
+ require 'async/ext/kernel'
@@ -1,40 +1,30 @@
1
1
  require 'async/task'
2
2
 
3
3
  class Array
4
- alias cycle_without_opal_async cycle
5
- def cycle(n=nil, &block)
6
- if Async::Task.started? && block_given?
7
- array = self * n unless n.nil?
8
- index = 0
9
- looper = lambda do
10
- if n.nil?
11
- block.call(self[index])
12
- index += 1
13
- index = index % self.size
14
- Async::Task.new(&looper)
15
- else
16
- block.call(array.shift)
17
- Async::Task.new(&looper) unless array.empty?
18
- end
4
+ def async_cycle(n=nil, &block)
5
+ array = self * n unless n.nil?
6
+ index = 0
7
+ looper = lambda do
8
+ if n.nil?
9
+ block.call(self[index])
10
+ index += 1
11
+ index = index % self.size
12
+ Async::Task.new(&looper)
13
+ else
14
+ block.call(array.shift)
15
+ Async::Task.new(&looper) unless array.empty?
19
16
  end
20
- Async::Task.new(&looper)
21
- else
22
- cycle_without_opal_async(n, &block)
23
17
  end
18
+ Async::Task.new(&looper)
24
19
  end
25
20
 
26
- alias each_without_opal_async each
27
- def each(&block)
28
- if Async::Task.started? && block_given?
29
- array = self
30
- index = 0
31
- looper = lambda do
32
- block.call(array.shift)
33
- Async::Task.new(&looper) unless array.empty?
34
- end
35
- Async::Task.new(&looper)
36
- else
37
- each_without_opal_async(&block)
21
+ def async_each(&block)
22
+ array = self
23
+ index = 0
24
+ looper = lambda do
25
+ block.call(array.shift)
26
+ Async::Task.new(&looper) unless array.empty?
38
27
  end
28
+ Async::Task.new(&looper)
39
29
  end
40
30
  end
@@ -0,0 +1,11 @@
1
+ require 'async/task'
2
+
3
+ module Kernel
4
+ def async_loop(&block)
5
+ looper = lambda do
6
+ block.call
7
+ Async::Task.new(&looper)
8
+ end
9
+ Async::Task.new(&looper)
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravenstine
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-08-18 00:00:00.000000000 Z
12
+ date: 2021-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opal
@@ -137,6 +137,7 @@ files:
137
137
  - opal/async/enumerator.rb
138
138
  - opal/async/ext.rb
139
139
  - opal/async/ext/array.rb
140
+ - opal/async/ext/kernel.rb
140
141
  - opal/async/ext/thread.rb
141
142
  - opal/async/interval.rb
142
143
  - opal/async/task.rb