opal-async 1.1.0 → 1.1.1

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: a38a4215b9b7cdde96a1e4d00c08c5940bd829c052281b93ba7286c31bab856a
4
- data.tar.gz: d329ce4369abd51128b468dc61fe26266fd96590688f55a6e2d934b631da831c
3
+ metadata.gz: 050f56171be0bacefeff4c68f9ba1e517b81adf3017b4013dcbeff44e8bbc331
4
+ data.tar.gz: 242811c68a22d384c2b6ce5e916fef95b729460b1dfab5a13e7891405c16d0e7
5
5
  SHA512:
6
- metadata.gz: 7d2373f2972e5402a14523f2975d544a2ba0faa4a2e68e527e4d27c3b327d279b687cccdda0b80ec34389149c0fa6d418e8faa04d9fc4b68f8f0ae96b679e1d4
7
- data.tar.gz: 13b4c95d7c39c6f5d7a0497156e40f72fc01ae96f5e32707a09b230bc3c2e81d803aae4bfd94315f956b005b892855aacdf59670824b5de99e3aa15c530f36ff
6
+ metadata.gz: 1265a3c27ccbbe5e9a78f2f734a16697b5d4cff3cfe7294c071b04c246f5530f7cca397592ff76683f4bfbc3682116d6c335bc4ca51dd4382b722cdd85ffbe2d
7
+ data.tar.gz: c260fc81573eea00cd1be33410655dbbbffec077d88fad31bb9f7f1c4941f04351dbaa1bb385e45e6fda67e0d4ee41d1f68a49f3c55e0639480e76383cddd01b
@@ -0,0 +1,9 @@
1
+ # Change Log
2
+
3
+ ## 1.1.1
4
+
5
+ - Added `Thread` class extension to enable using `Async::Task` as `Thread` in Opal
6
+
7
+ ## 1.1.0
8
+
9
+ - Initial version
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Opal: Async
2
+ [![Gem Version](https://badge.fury.io/rb/opal-async.svg)](https://badge.fury.io/rb/opal-async)
2
3
 
3
4
  ## Installation
4
5
 
5
6
  Add this line to your application's Gemfile:
6
7
 
7
- gem 'opal-async', github: "ravenstine/opal-async
8
+ gem 'opal-async', '~> 1.1.1'
8
9
 
9
10
  And then execute:
10
11
 
@@ -14,12 +15,11 @@ Or install it yourself as:
14
15
 
15
16
  $ gem install opal-async
16
17
 
17
- Then require 'opal-async' in both your Opal code and your Opal compilation environment.
18
-
18
+ Then require 'opal-async' in both your [Opal](https://opalrb.com/) code and your Opal compilation environment.
19
19
 
20
20
  ## Usage
21
21
 
22
- #### Enumerator
22
+ ### Enumerator
23
23
 
24
24
  The enumerator provides iteration methods for any enumerable object. These methods are 'non-blocking', so other operations in the event loop can continue to be executed in between iterations. Beware, this is not faster than a normal blocking iteration; it is trading off performance for not blocking other operations you may want to have continue such as UI updates & camera frame capture. Very large arrays will take a long time to finish while the overhead may not be noticeable for smaller arrays. It is best to do some tests and assess whether the trade-off is balanced enough for your needs.
25
25
 
@@ -43,21 +43,21 @@ enumerator.map{|x| x + 2}.each_slice(3).each{|x| puts x}
43
43
  #=> [9,10,11]
44
44
  ```
45
45
 
46
- ##### Available enumerator methods:
46
+ #### Available enumerator methods:
47
47
  - each
48
48
  - map
49
49
  - each_slice
50
50
  - select
51
51
  - reject
52
52
 
53
- #### Task
53
+ ### Task
54
54
  A task contains code that will be added to the call stack of the event loop. The Enumerator uses tasks to run small chunks of code without blocking the event loop. A task can do the same things that a Timeout or an Interval can do but with some added features and optimizations.
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
58
  Example:
59
59
 
60
- ```
60
+ ```ruby
61
61
  Async::Task.new do
62
62
  puts "hello world"
63
63
  end
@@ -67,7 +67,7 @@ end
67
67
 
68
68
  By default, a task will only run once. To make a task repeat, set the option times to however many times you want the task to repeat. You can also have access to countup and countdown variables.
69
69
 
70
- ```
70
+ ```ruby
71
71
  Async::Task.new do times: 5 do |countup, countdown|
72
72
  puts countdown
73
73
  end
@@ -81,7 +81,7 @@ end
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
 
84
- ```
84
+ ```ruby
85
85
  Async::Task.new times: :infinite do
86
86
  puts "forever"
87
87
  end
@@ -95,7 +95,7 @@ end
95
95
 
96
96
  The step option will determine how much you want your task to "step".
97
97
 
98
- ```
98
+ ```ruby
99
99
  Async::Task.new times: 10, step: 2 do |countup, countdown|
100
100
  puts countup
101
101
  end
@@ -109,7 +109,7 @@ end
109
109
 
110
110
  To set a delay time on your task, specify the delay option with the number of milliseconds you want the duration of the delay to be. This can also be done when you have set your task to repeat.
111
111
 
112
- ```
112
+ ```ruby
113
113
  Async::Task.new delay: 1000 do
114
114
  puts "this took 1 second"
115
115
  end
@@ -117,7 +117,7 @@ end
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:
119
119
 
120
- ```
120
+ ```ruby
121
121
  task = Async::Task.new times: 5, delay: 5000 do |countup, countdown|
122
122
  puts countdown
123
123
  task.delay = task.delay - 1000
@@ -128,7 +128,7 @@ Tasks also have callbacks that can be performed on certain events.
128
128
 
129
129
  Here is an example of how to execute code after a repeating task has finished:
130
130
 
131
- ```
131
+ ```ruby
132
132
  task = Async::Task.new times: 3, delay: 1000 do |countup, countdown|
133
133
  puts countdown
134
134
  end
@@ -144,24 +144,45 @@ task.on_finish {puts "BOOM"}
144
144
  Other callbacks include ```on_start``` and ```on_stop```.
145
145
 
146
146
 
147
- #### Other Timers
147
+ ### Other Timers
148
148
 
149
- You can also timeouts and intervals specifically:
149
+ You can also set timeouts and intervals, specifically:
150
150
 
151
151
 
152
- ```
153
- Timeout.new 3000 do
152
+ ```ruby
153
+ Async::Timeout.new 3000 do
154
154
  puts "I just waited 3 seconds."
155
155
  end
156
156
  ```
157
157
 
158
- ```
159
- Interval.new 3000 do
158
+ ```ruby
159
+ Async::Interval.new 3000 do
160
160
  puts "I'm going to do this every 3 seconds."
161
161
  end
162
162
  ```
163
163
 
164
+ ### Thread
165
+
166
+ You may use the `Async::Task` class as a `Thread` class in Opal to perform asynchronous work with an extra `require` statement.
167
+
168
+ ```ruby
169
+ require 'async/ext/thread'
170
+
171
+ Thread.new do
172
+ puts "hello world"
173
+ end
174
+ ```
175
+
176
+ ## In The Wild
177
+
178
+ opal-async is currently used in the following projects:
179
+ - [Glimmer DSL for Opal](https://github.com/AndyObtiva/glimmer-dsl-opal)
180
+
181
+ ## Change Log
182
+
183
+ [CHANGELOG.md](CHANGELOG.md)
184
+
164
185
  ## Contributors
165
186
 
166
187
  - [Benjamin Titcomb](https://github.com/Ravenstine) (Creator and Main Contributor)
167
- - [Andy Maleh](https://github.com/AndyObtiva) (Gemifier)
188
+ - [Andy Maleh](https://github.com/AndyObtiva) (Gemifier and Maintainer)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -0,0 +1,9 @@
1
+ require 'thread' # bring the thread compatibility class from Opal first
2
+
3
+ class Thread
4
+ def initialize(*args, &proc)
5
+ Async::Task.new do
6
+ proc.call(*args)
7
+ end
8
+ end
9
+ end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravenstine
8
8
  - Andy Maleh
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-20 00:00:00.000000000 Z
12
+ date: 2020-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: opal
@@ -108,9 +108,11 @@ email:
108
108
  executables: []
109
109
  extensions: []
110
110
  extra_rdoc_files:
111
+ - CHANGELOG.md
111
112
  - LICENSE.txt
112
113
  - README.md
113
114
  files:
115
+ - CHANGELOG.md
114
116
  - LICENSE.txt
115
117
  - README.md
116
118
  - VERSION
@@ -119,6 +121,7 @@ files:
119
121
  - opal/async.rb
120
122
  - opal/async/countdown.rb
121
123
  - opal/async/enumerator.rb
124
+ - opal/async/ext/thread.rb
122
125
  - opal/async/interval.rb
123
126
  - opal/async/task.rb
124
127
  - opal/async/timeout.rb
@@ -127,7 +130,7 @@ homepage: http://github.com/AndyObtiva/opal-async
127
130
  licenses:
128
131
  - MIT
129
132
  metadata: {}
130
- post_install_message:
133
+ post_install_message:
131
134
  rdoc_options:
132
135
  - "--main"
133
136
  - README
@@ -148,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
151
  version: '0'
149
152
  requirements: []
150
153
  rubygems_version: 3.1.2
151
- signing_key:
154
+ signing_key:
152
155
  specification_version: 4
153
156
  summary: Provides non-blocking tasks and enumerators for Opal.
154
157
  test_files: []