opal-async 1.2.0 → 1.3.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: e4ac70e28d27ce5551acbba060dba2956e791e33ab7788673ffd6ebfc08fc35f
4
- data.tar.gz: c02be17a79bab91865aa0898afc97a024376bf0c7686dd85854193fd4174516a
3
+ metadata.gz: cc5f4a757a39dabc8a7bc7efcb87631a7dd6809f0fd7da29b5b40ec23d436ea8
4
+ data.tar.gz: b7c60f66044d9e0f49c2b0a49c18046bccfbd89364fbbdb18d62323cf5351991
5
5
  SHA512:
6
- metadata.gz: 1cd290ff3f7b6173e7d6cf6440bca1819e53294a2a7859a016bf0e2632cc7b43b5a18f5563d21be0b755e7018cf5449f5f1e6e18a3217a44d950d580cd4eac57
7
- data.tar.gz: 0bc9487d71ce6343d0b708c56c6878bb445390db5043a5972221723ffec12059286f03486424f0b480441a46bb4d9af0407028444f0a119a2dd3b566031ba7e7
6
+ metadata.gz: bc8669beff060d5f91ffad0b6f1ee68d4708124bb5be87d6759eb67ee7c84211c9a6c6a624a73c1eca170ccb305817d13f6472c9c9986c5488b4afbf918929c1
7
+ data.tar.gz: cf3fe071bb8e549e76e447a5bfd1e28afceb6385a6f005dbef96a8a2b0c77596fbcbeeb05e9901933f151da36d307353dc4c8c13f02fedb39302f2015a2b6d35
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.3.0
4
+
5
+ - Asynchronous `Array#each` method that is web browser event loop friendly
6
+ - `Thread#kill` and `Thread#stop` for partial-compatibility with Ruby `Thread`
7
+
3
8
  ## 1.2.0
4
9
 
5
10
  - Asynchronous `Array#cycle` method that is web browser event loop friendly
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Add this line to your application's Gemfile:
7
7
 
8
- gem 'opal-async', '~> 1.2.0'
8
+ gem 'opal-async', '~> 1.3.0'
9
9
 
10
10
  And then execute:
11
11
 
@@ -55,7 +55,7 @@ A task contains code that will be added to the call stack of the event loop. Th
55
55
 
56
56
  With no options provided, a task will be run immediately once the event loop comes back to it(if the environment supports this). If the environment does not support immediates, it will attempt to polyfill an immediate before falling back on a 0ms timeout.
57
57
 
58
- Example:
58
+ Example:
59
59
 
60
60
  ```ruby
61
61
  Async::Task.new do
@@ -77,7 +77,7 @@ end
77
77
  #=> 3
78
78
  #=> 2
79
79
  #=> 1
80
- ```
80
+ ```
81
81
 
82
82
  To make a task repeat infinitely, set times to ```:infinite```, or repeat to ```true```. A countup will be provided but no countdown. You can also use ```:i``` for short.
83
83
 
@@ -112,7 +112,7 @@ To set a delay time on your task, specify the delay option with the number of mi
112
112
  ```ruby
113
113
  Async::Task.new delay: 1000 do
114
114
  puts "this took 1 second"
115
- end
115
+ end
116
116
  ```
117
117
 
118
118
  The delay and steps of a task can be modified within the execution of the task. The following example will start out slow and increase in speed:
@@ -185,15 +185,19 @@ end
185
185
 
186
186
  #### Array
187
187
 
188
- `Array#cycle` has been amended to work asynchronously via `Async::Task` when triggered inside another `Async::Task` (auto-detects it)
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`
191
+
192
+ This makes them not block the web browser event loop, thus allowing other tasks to update the DOM unhindered while running.
189
193
 
190
- This makes it not block the web browser event loop, thus allowing other tasks to update the DOM unhindered while `Array#cycle` is running.
194
+ Example:
191
195
 
192
196
  ```ruby
193
197
  require 'async/ext/array' # not needed if you called `require 'async/ext'`
194
198
 
195
199
  Async::Task.new do
196
- [1,2,3,4].cycle do |n|
200
+ [1,2,3,4].cycle do |n|
197
201
  puts n
198
202
  Async::Task.new do
199
203
  # make a DOM update
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
@@ -22,4 +22,19 @@ class Array
22
22
  cycle_without_opal_async(n, &block)
23
23
  end
24
24
  end
25
+
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)
38
+ end
39
+ end
25
40
  end
@@ -2,8 +2,16 @@ require 'thread' # bring the thread compatibility class from Opal first
2
2
 
3
3
  class Thread
4
4
  def initialize(*args, &proc)
5
- Async::Task.new do
5
+ @async_task = Async::Task.new do
6
6
  proc.call(*args)
7
7
  end
8
8
  end
9
+
10
+ def stop
11
+ @async_task.stop
12
+ end
13
+
14
+ def kill
15
+ @async_task.stop
16
+ end
9
17
  end
data/opal/async/task.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Async
2
2
  class Task
3
3
  class << self
4
- # returns general status of whether a task is running.
5
- # Useful to code running in the task block to determine if it is running
4
+ # returns general status of whether a task is running.
5
+ # Useful to code running in the task block to determine if it is running
6
6
  # as part of a task or not and take special actions accordingly.
7
7
  def started?
8
8
  @@started = false unless defined? :@@started
@@ -130,9 +130,9 @@ module Async
130
130
  };
131
131
  var mc = new MessageChannel();
132
132
 
133
- mc.port1.onmessage = function(){
133
+ mc.port1.onmessage = function(){
134
134
  if (!#{stopped?}){
135
- task.apply(task)
135
+ task.apply(task)
136
136
  }
137
137
  };
138
138
  mc.port2.postMessage(null);
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.2.0
4
+ version: 1.3.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: 2020-10-11 00:00:00.000000000 Z
12
+ date: 2021-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opal
@@ -101,6 +101,20 @@ dependencies:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
+ - !ruby/object:Gem::Dependency
105
+ name: rake-tui
106
+ requirement: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
104
118
  description: Provides non-blocking tasks and enumerators for Opal.
105
119
  email:
106
120
  - benjamin@pixelstreetinc.com