asynchronizer 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/asynchronizer/version.rb +1 -1
- data/vendor/assets/javascripts/asynchronizer.coffee +17 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52da27ccc15215f7011b301faeb3f2b868db92fc
|
4
|
+
data.tar.gz: f633668ba2bd93e7f0577c1fb0493ecff2c327db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edf988b288ba471a6c1c93eb53cde80b76d4561e8bdfa6c367752a789376c602f4902a5c0506231c69ce2fa98226309552d6587b10c430f38987e25ceab11ea8
|
7
|
+
data.tar.gz: d2a7d32b3c856b7d6b071fe37699d8e4999105ddf3e6683ac4a6679cdf5aa2055143cd0af037d04c8b6fa1197f45acfc8f4be30b10e243506be4d935863c0191
|
@@ -1,14 +1,12 @@
|
|
1
1
|
# Collects data from asynchronous events.
|
2
2
|
|
3
|
-
class
|
3
|
+
class Asynchronizer
|
4
4
|
|
5
|
-
# conditions:
|
6
|
-
|
7
|
-
# Provides the collected data.
|
8
|
-
constructor: (conditions, callback) ->
|
5
|
+
# conditions: Array of simple conditions to wait for.
|
6
|
+
constructor: (conditions) ->
|
9
7
|
|
10
8
|
# The callback to call when all conditions are fulfilled.
|
11
|
-
@callback =
|
9
|
+
@callback = undefined
|
12
10
|
|
13
11
|
# The conditions that still need to be fulfilled before we are done
|
14
12
|
# and can call the callback.
|
@@ -22,5 +20,17 @@ class window.Asynchronizer
|
|
22
20
|
check: (condition, value) ->
|
23
21
|
@values.push value if value
|
24
22
|
@remaining_conditions = _.without @remaining_conditions, condition
|
25
|
-
|
23
|
+
@_check_and_fire_conditions()
|
24
|
+
|
25
|
+
|
26
|
+
# Checks the conditions and fires them if this is the time.
|
27
|
+
_check_and_fire_conditions: ->
|
28
|
+
if @remaining_conditions.length is 0 and @callback
|
26
29
|
@callback @values
|
30
|
+
|
31
|
+
|
32
|
+
# Sets the callback to be called when done.
|
33
|
+
then: (callback) ->
|
34
|
+
@callback = callback
|
35
|
+
@_check_and_fire_conditions()
|
36
|
+
|