opal-async 1.3.0 → 1.4.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +28 -6
- data/VERSION +1 -1
- data/opal/async/ext.rb +1 -0
- data/opal/async/ext/array.rb +20 -30
- data/opal/async/ext/kernel.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcf44d0cb1a3c702b3c60521a2e173b7a3824fd8a37e80cd0fb18d5c4e0ffc2c
|
4
|
+
data.tar.gz: 28e4364132c94e690752669a3211796ec2b3423314a0db4892348d92fb0beb46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
189
|
-
- `Array#
|
190
|
-
- `Array#
|
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].
|
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)
|
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.
|
1
|
+
1.4.0
|
data/opal/async/ext.rb
CHANGED
data/opal/async/ext/array.rb
CHANGED
@@ -1,40 +1,30 @@
|
|
1
1
|
require 'async/task'
|
2
2
|
|
3
3
|
class Array
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
looper
|
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
|
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.
|
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-
|
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
|