celluloid 0.1.0 → 0.2.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.
@@ -1,5 +1,5 @@
1
1
  !RBIX
2
- 3578385345186687227
2
+ 3246536075095810518
3
3
  18
4
4
  M
5
5
  1
@@ -1,5 +1,5 @@
1
1
  !RBIX
2
- 3578385345186687227
2
+ 3246536075095810518
3
3
  18
4
4
  M
5
5
  1
@@ -1,5 +1,5 @@
1
1
  !RBIX
2
- 3578385345186687227
2
+ 3246536075095810518
3
3
  18
4
4
  M
5
5
  1
@@ -1,28 +1,61 @@
1
+ require 'thread'
2
+
1
3
  module Celluloid
4
+ # Create a new Celluloid::Future object, allowing a block to be computed in
5
+ # the background and its return value obtained later
2
6
  def self.Future(*args, &block)
3
- future = Celluloid::Future.spawn(*args, &block)
4
- future.run!
5
- future
7
+ Celluloid::Future.new(*args, &block)
6
8
  end
7
9
 
10
+ # Celluloid::Future objects allow methods and blocks to run in the
11
+ # background, their values requested later
8
12
  class Future
9
- include Celluloid::Actor
10
-
11
13
  def initialize(*args, &block)
12
- @args, @block = args, block
14
+ @lock = Mutex.new
15
+ @value_obtained = false
16
+
17
+ @runner = Runner.new(*args, &block)
18
+ @runner.run!
13
19
  end
14
20
 
15
- def run
16
- @called = true
17
- @value = @block[*@args]
18
- rescue Exception => error
19
- @error = error
21
+ # Obtain the value for this Future
22
+ def value
23
+ @lock.synchronize do
24
+ unless @value_obtained
25
+ @value = @runner.value
26
+ @runner.terminate
27
+ @value_obtained = true
28
+ end
29
+
30
+ @value
31
+ end
20
32
  end
21
33
 
22
- def value
23
- raise "not run yet" unless @called
24
- abort @error if @error
25
- @value
34
+ # Inspect this Celluloid::Future
35
+ alias_method :inspect, :to_s
36
+
37
+ # Runner is an internal class which executes the given block/method
38
+ class Runner
39
+ include Celluloid
40
+
41
+ def initialize(*args, &block)
42
+ @args, @block = args, block
43
+ end
44
+
45
+ def run
46
+ @value = @block.call(*@args)
47
+ rescue Exception => error
48
+ @error = error
49
+ ensure
50
+ @called = true
51
+ signal :finished
52
+ end
53
+
54
+ def value
55
+ wait :finished unless @called
56
+ abort @error if @error
57
+ @value
58
+ end
26
59
  end
27
60
  end
28
61
  end
@@ -1,5 +1,5 @@
1
1
  !RBIX
2
- 3578385345186687227
2
+ 3246536075095810518
3
3
  18
4
4
  M
5
5
  1
@@ -9,31 +9,40 @@ x
9
9
  10
10
10
  __script__
11
11
  i
12
- 28
13
- 99
12
+ 37
13
+ 5
14
14
  7
15
15
  0
16
- 65
16
+ 64
17
+ 47
17
18
  49
18
19
  1
20
+ 1
21
+ 15
22
+ 99
23
+ 7
24
+ 2
25
+ 65
26
+ 49
27
+ 3
19
28
  2
20
29
  13
21
30
  99
22
31
  12
23
32
  7
24
- 2
33
+ 4
25
34
  12
26
35
  7
27
- 3
36
+ 5
28
37
  12
29
38
  65
30
39
  12
31
40
  49
32
- 4
41
+ 6
33
42
  4
34
43
  15
35
44
  49
36
- 2
45
+ 4
37
46
  0
38
47
  15
39
48
  2
@@ -50,7 +59,13 @@ I
50
59
  0
51
60
  n
52
61
  p
53
- 5
62
+ 7
63
+ s
64
+ 6
65
+ thread
66
+ x
67
+ 7
68
+ require
54
69
  x
55
70
  9
56
71
  Celluloid
@@ -133,7 +148,7 @@ x
133
148
  6
134
149
  Future
135
150
  i
136
- 40
151
+ 29
137
152
  95
138
153
  19
139
154
  1
@@ -162,22 +177,240 @@ i
162
177
  51
163
178
  5
164
179
  0
165
- 19
180
+ 11
181
+ I
182
+ 6
183
+ I
166
184
  2
185
+ I
186
+ 0
187
+ I
188
+ 0
189
+ I
190
+ 0
191
+ I
192
+ 0
193
+ p
194
+ 6
195
+ x
196
+ 9
197
+ Celluloid
198
+ n
199
+ x
200
+ 6
201
+ Future
202
+ x
203
+ 4
204
+ Proc
205
+ x
206
+ 14
207
+ __from_block__
208
+ x
209
+ 3
210
+ new
211
+ p
212
+ 5
213
+ I
214
+ -1
215
+ I
216
+ 6
217
+ I
218
+ 4
219
+ I
220
+ 7
221
+ I
222
+ 1d
223
+ x
224
+ 49
225
+ /Users/tony/src/celluloid/lib/celluloid/future.rb
226
+ p
227
+ 2
228
+ x
229
+ 4
230
+ args
231
+ x
232
+ 5
233
+ block
234
+ x
235
+ 13
236
+ attach_method
237
+ x
238
+ 10
239
+ open_class
240
+ x
241
+ 14
242
+ __class_init__
243
+ M
244
+ 1
245
+ n
246
+ n
247
+ x
248
+ 6
249
+ Future
250
+ i
251
+ 67
252
+ 5
253
+ 66
254
+ 99
255
+ 7
256
+ 0
257
+ 7
258
+ 1
259
+ 65
260
+ 67
261
+ 49
262
+ 2
263
+ 0
264
+ 49
265
+ 3
266
+ 4
167
267
  15
168
- 20
268
+ 99
269
+ 7
270
+ 4
271
+ 7
272
+ 5
273
+ 65
274
+ 67
275
+ 49
169
276
  2
277
+ 0
278
+ 49
279
+ 3
280
+ 4
281
+ 15
282
+ 5
283
+ 7
284
+ 6
285
+ 7
286
+ 7
287
+ 47
170
288
  49
289
+ 8
290
+ 2
291
+ 15
292
+ 99
293
+ 7
294
+ 9
295
+ 1
296
+ 65
297
+ 49
298
+ 10
299
+ 3
300
+ 13
301
+ 99
302
+ 12
303
+ 7
304
+ 11
305
+ 12
306
+ 7
307
+ 12
308
+ 12
309
+ 65
310
+ 12
311
+ 49
312
+ 13
313
+ 4
314
+ 15
315
+ 49
316
+ 11
317
+ 0
318
+ 11
319
+ I
171
320
  6
321
+ I
322
+ 0
323
+ I
324
+ 0
325
+ I
326
+ 0
327
+ I
172
328
  0
329
+ n
330
+ p
331
+ 14
332
+ x
333
+ 10
334
+ initialize
335
+ M
336
+ 1
337
+ n
338
+ n
339
+ x
340
+ 10
341
+ initialize
342
+ i
343
+ 66
344
+ 95
345
+ 19
346
+ 1
347
+ 15
348
+ 45
349
+ 0
350
+ 1
351
+ 13
352
+ 71
353
+ 2
354
+ 47
355
+ 9
356
+ 25
357
+ 47
358
+ 49
359
+ 3
360
+ 0
361
+ 13
362
+ 47
363
+ 49
364
+ 4
365
+ 0
366
+ 15
367
+ 8
368
+ 28
369
+ 49
370
+ 2
371
+ 0
372
+ 38
373
+ 5
374
+ 15
375
+ 3
376
+ 38
377
+ 6
173
378
  15
379
+ 45
380
+ 7
381
+ 8
382
+ 20
383
+ 0
384
+ 36
174
385
  20
386
+ 1
387
+ 13
388
+ 70
389
+ 10
390
+ 54
391
+ 44
392
+ 43
393
+ 9
394
+ 12
395
+ 49
396
+ 10
397
+ 1
398
+ 51
175
399
  2
400
+ 0
401
+ 38
402
+ 11
403
+ 15
404
+ 39
405
+ 11
406
+ 49
407
+ 12
408
+ 0
176
409
  11
177
410
  I
178
- 7
411
+ 6
179
412
  I
180
- 3
413
+ 2
181
414
  I
182
415
  0
183
416
  I
@@ -187,14 +420,30 @@ I
187
420
  I
188
421
  0
189
422
  p
190
- 7
423
+ 13
191
424
  x
192
- 9
193
- Celluloid
425
+ 5
426
+ Mutex
194
427
  n
195
428
  x
429
+ 3
430
+ new
431
+ x
432
+ 8
433
+ allocate
434
+ x
435
+ 10
436
+ initialize
437
+ x
438
+ 5
439
+ @lock
440
+ x
441
+ 15
442
+ @value_obtained
443
+ x
196
444
  6
197
- Future
445
+ Runner
446
+ n
198
447
  x
199
448
  4
200
449
  Proc
@@ -202,48 +451,224 @@ x
202
451
  14
203
452
  __from_block__
204
453
  x
454
+ 7
455
+ @runner
456
+ x
457
+ 4
458
+ run!
459
+ p
460
+ 11
461
+ I
462
+ -1
463
+ I
464
+ d
465
+ I
466
+ 4
467
+ I
468
+ e
469
+ I
470
+ 1f
471
+ I
472
+ f
473
+ I
474
+ 23
475
+ I
476
+ 11
477
+ I
478
+ 3c
479
+ I
480
+ 12
481
+ I
482
+ 42
483
+ x
484
+ 49
485
+ /Users/tony/src/celluloid/lib/celluloid/future.rb
486
+ p
487
+ 2
488
+ x
489
+ 4
490
+ args
491
+ x
492
+ 5
493
+ block
494
+ x
495
+ 17
496
+ method_visibility
497
+ x
498
+ 15
499
+ add_defn_method
500
+ x
205
501
  5
206
- spawn
502
+ value
503
+ M
504
+ 1
505
+ n
506
+ n
507
+ x
508
+ 5
509
+ value
510
+ i
511
+ 8
512
+ 39
513
+ 0
514
+ 56
515
+ 1
516
+ 50
517
+ 2
518
+ 0
519
+ 11
520
+ I
521
+ 2
522
+ I
523
+ 0
524
+ I
525
+ 0
526
+ I
527
+ 0
528
+ I
529
+ 0
530
+ n
531
+ p
532
+ 3
533
+ x
534
+ 5
535
+ @lock
536
+ M
537
+ 1
538
+ p
539
+ 2
540
+ x
541
+ 9
542
+ for_block
543
+ t
544
+ n
545
+ x
546
+ 5
547
+ value
548
+ i
549
+ 28
550
+ 39
551
+ 0
552
+ 9
553
+ 7
554
+ 1
555
+ 8
556
+ 24
557
+ 39
558
+ 1
559
+ 49
560
+ 2
561
+ 0
562
+ 38
563
+ 3
564
+ 15
565
+ 39
566
+ 1
567
+ 49
568
+ 4
569
+ 0
570
+ 15
571
+ 2
572
+ 38
573
+ 0
574
+ 15
575
+ 39
576
+ 3
577
+ 11
578
+ I
579
+ 2
580
+ I
581
+ 0
582
+ I
583
+ 0
584
+ I
585
+ 0
586
+ I
587
+ 0
588
+ I
589
+ -2
590
+ p
591
+ 5
592
+ x
593
+ 15
594
+ @value_obtained
595
+ x
596
+ 7
597
+ @runner
598
+ x
599
+ 5
600
+ value
601
+ x
602
+ 6
603
+ @value
604
+ x
605
+ 9
606
+ terminate
607
+ p
608
+ 13
609
+ I
610
+ 0
611
+ I
612
+ 18
613
+ I
614
+ 7
615
+ I
616
+ 19
617
+ I
618
+ f
619
+ I
620
+ 1a
621
+ I
622
+ 15
623
+ I
624
+ 1b
625
+ I
626
+ 18
627
+ I
628
+ 0
629
+ I
630
+ 19
631
+ I
632
+ 1e
633
+ I
634
+ 1c
635
+ x
636
+ 49
637
+ /Users/tony/src/celluloid/lib/celluloid/future.rb
638
+ p
639
+ 0
207
640
  x
208
- 4
209
- run!
641
+ 11
642
+ synchronize
210
643
  p
211
- 9
644
+ 5
212
645
  I
213
646
  -1
214
647
  I
215
- 2
216
- I
217
- 4
218
- I
219
- 3
220
- I
221
- 1f
222
- I
223
- 4
648
+ 16
224
649
  I
225
- 25
650
+ 0
226
651
  I
227
- 5
652
+ 17
228
653
  I
229
- 28
654
+ 8
230
655
  x
231
656
  49
232
657
  /Users/tony/src/celluloid/lib/celluloid/future.rb
233
658
  p
234
- 3
659
+ 0
660
+ x
661
+ 7
662
+ inspect
235
663
  x
236
664
  4
237
- args
665
+ to_s
238
666
  x
239
- 5
240
- block
667
+ 12
668
+ alias_method
241
669
  x
242
670
  6
243
- future
244
- x
245
- 13
246
- attach_method
671
+ Runner
247
672
  x
248
673
  10
249
674
  open_class
@@ -256,62 +681,60 @@ n
256
681
  n
257
682
  x
258
683
  6
259
- Future
684
+ Runner
260
685
  i
261
- 55
686
+ 53
262
687
  5
263
688
  66
264
689
  5
265
690
  45
266
691
  0
267
692
  1
268
- 43
269
- 2
270
693
  47
271
694
  49
272
- 3
695
+ 2
273
696
  1
274
697
  15
275
698
  99
276
699
  7
277
- 4
700
+ 3
278
701
  7
279
- 5
702
+ 4
280
703
  65
281
704
  67
282
705
  49
283
- 6
706
+ 5
284
707
  0
285
708
  49
286
- 7
709
+ 6
287
710
  4
288
711
  15
289
712
  99
290
713
  7
291
- 8
292
714
  7
293
- 9
715
+ 7
716
+ 8
294
717
  65
295
718
  67
296
719
  49
297
- 6
720
+ 5
298
721
  0
299
722
  49
300
- 7
723
+ 6
301
724
  4
302
725
  15
303
726
  99
304
727
  7
305
- 10
728
+ 9
306
729
  7
307
- 11
730
+ 10
308
731
  65
309
732
  67
310
733
  49
311
- 6
734
+ 5
312
735
  0
313
736
  49
314
- 7
737
+ 6
315
738
  4
316
739
  11
317
740
  I
@@ -326,15 +749,12 @@ I
326
749
  0
327
750
  n
328
751
  p
329
- 12
752
+ 11
330
753
  x
331
754
  9
332
755
  Celluloid
333
756
  n
334
757
  x
335
- 5
336
- Actor
337
- x
338
758
  7
339
759
  include
340
760
  x
@@ -392,11 +812,11 @@ p
392
812
  I
393
813
  -1
394
814
  I
395
- b
815
+ 29
396
816
  I
397
817
  4
398
818
  I
399
- c
819
+ 2a
400
820
  I
401
821
  12
402
822
  x
@@ -427,49 +847,52 @@ x
427
847
  3
428
848
  run
429
849
  i
430
- 63
850
+ 96
851
+ 29
852
+ 68
853
+ 1
431
854
  26
432
855
  93
433
856
  0
434
857
  15
858
+ 26
859
+ 93
860
+ 1
861
+ 15
435
862
  29
436
- 25
863
+ 28
437
864
  0
438
- 2
439
- 38
865
+ 39
440
866
  0
441
- 15
442
867
  39
443
868
  1
444
- 39
445
- 2
446
869
  36
447
870
  1
448
871
  51
449
- 3
872
+ 2
450
873
  0
451
874
  38
452
- 4
875
+ 3
453
876
  30
454
877
  8
455
- 59
878
+ 62
456
879
  26
457
880
  93
458
- 1
881
+ 2
459
882
  15
460
883
  24
461
884
  13
462
885
  45
886
+ 4
463
887
  5
464
- 6
465
888
  12
466
889
  49
467
- 7
890
+ 6
468
891
  1
469
892
  10
470
- 42
893
+ 45
471
894
  8
472
- 54
895
+ 57
473
896
  15
474
897
  24
475
898
  19
@@ -478,21 +901,51 @@ i
478
901
  20
479
902
  0
480
903
  38
481
- 8
904
+ 7
482
905
  25
483
906
  8
484
- 59
907
+ 62
485
908
  15
486
909
  92
487
- 1
910
+ 2
488
911
  27
489
912
  34
490
913
  92
491
- 0
914
+ 1
915
+ 27
916
+ 30
917
+ 8
918
+ 83
919
+ 26
920
+ 2
921
+ 38
922
+ 8
923
+ 15
924
+ 5
925
+ 7
926
+ 9
927
+ 47
928
+ 49
929
+ 10
930
+ 1
931
+ 15
492
932
  27
933
+ 34
934
+ 2
935
+ 38
936
+ 8
937
+ 15
938
+ 5
939
+ 7
940
+ 9
941
+ 47
942
+ 49
943
+ 10
944
+ 1
945
+ 15
493
946
  11
494
947
  I
495
- 6
948
+ 7
496
949
  I
497
950
  1
498
951
  I
@@ -503,10 +956,7 @@ I
503
956
  0
504
957
  n
505
958
  p
506
- 9
507
- x
508
- 7
509
- @called
959
+ 11
510
960
  x
511
961
  6
512
962
  @block
@@ -514,8 +964,8 @@ x
514
964
  5
515
965
  @args
516
966
  x
517
- 2
518
- []
967
+ 4
968
+ call
519
969
  x
520
970
  6
521
971
  @value
@@ -529,46 +979,75 @@ x
529
979
  x
530
980
  6
531
981
  @error
982
+ x
983
+ 7
984
+ @called
985
+ x
986
+ 8
987
+ finished
988
+ x
989
+ 6
990
+ signal
532
991
  p
533
- 19
992
+ 29
534
993
  I
535
994
  -1
536
995
  I
537
- f
996
+ 2d
538
997
  I
539
998
  0
540
999
  I
541
- 10
1000
+ 2e
542
1001
  I
543
- b
1002
+ 7
544
1003
  I
545
- 11
1004
+ 34
546
1005
  I
547
- 19
1006
+ e
548
1007
  I
549
- 0
1008
+ 2e
550
1009
  I
551
- 1e
1010
+ 1c
552
1011
  I
553
- 12
1012
+ 0
554
1013
  I
555
- 2b
1014
+ 21
556
1015
  I
557
- 14
1016
+ 2f
558
1017
  I
559
- 2c
1018
+ 2e
560
1019
  I
561
- 12
1020
+ 31
562
1021
  I
563
1022
  2f
564
1023
  I
565
- 13
1024
+ 2f
1025
+ I
1026
+ 32
1027
+ I
1028
+ 30
566
1029
  I
567
- 3b
1030
+ 3e
568
1031
  I
569
1032
  0
570
1033
  I
571
- 3f
1034
+ 45
1035
+ I
1036
+ 32
1037
+ I
1038
+ 49
1039
+ I
1040
+ 33
1041
+ I
1042
+ 53
1043
+ I
1044
+ 32
1045
+ I
1046
+ 57
1047
+ I
1048
+ 33
1049
+ I
1050
+ 60
572
1051
  x
573
1052
  49
574
1053
  /Users/tony/src/celluloid/lib/celluloid/future.rb
@@ -588,18 +1067,17 @@ x
588
1067
  5
589
1068
  value
590
1069
  i
591
- 34
1070
+ 33
592
1071
  39
593
1072
  0
594
1073
  9
595
1074
  7
596
1075
  1
597
1076
  8
598
- 15
1077
+ 14
599
1078
  5
600
1079
  7
601
1080
  1
602
- 64
603
1081
  47
604
1082
  49
605
1083
  2
@@ -608,7 +1086,7 @@ i
608
1086
  39
609
1087
  3
610
1088
  9
611
- 29
1089
+ 28
612
1090
  5
613
1091
  39
614
1092
  3
@@ -617,7 +1095,7 @@ i
617
1095
  4
618
1096
  1
619
1097
  8
620
- 30
1098
+ 29
621
1099
  1
622
1100
  15
623
1101
  39
@@ -639,12 +1117,12 @@ p
639
1117
  x
640
1118
  7
641
1119
  @called
642
- s
643
- 11
644
- not run yet
645
1120
  x
646
- 5
647
- raise
1121
+ 8
1122
+ finished
1123
+ x
1124
+ 4
1125
+ wait
648
1126
  x
649
1127
  6
650
1128
  @error
@@ -659,29 +1137,29 @@ p
659
1137
  I
660
1138
  -1
661
1139
  I
662
- 16
1140
+ 36
663
1141
  I
664
1142
  0
665
1143
  I
666
- 17
1144
+ 37
667
1145
  I
668
- f
1146
+ e
669
1147
  I
670
1148
  0
671
1149
  I
672
- 10
1150
+ f
673
1151
  I
674
- 18
1152
+ 38
675
1153
  I
676
- 1e
1154
+ 1d
677
1155
  I
678
1156
  0
679
1157
  I
680
- 1f
1158
+ 1e
681
1159
  I
682
- 19
1160
+ 39
683
1161
  I
684
- 22
1162
+ 21
685
1163
  x
686
1164
  49
687
1165
  /Users/tony/src/celluloid/lib/celluloid/future.rb
@@ -692,21 +1170,49 @@ p
692
1170
  I
693
1171
  2
694
1172
  I
1173
+ 27
1174
+ I
1175
+ b
1176
+ I
1177
+ 29
1178
+ I
1179
+ 19
1180
+ I
1181
+ 2d
1182
+ I
1183
+ 27
1184
+ I
1185
+ 36
1186
+ I
1187
+ 35
1188
+ x
1189
+ 49
1190
+ /Users/tony/src/celluloid/lib/celluloid/future.rb
1191
+ p
1192
+ 0
1193
+ x
1194
+ 13
1195
+ attach_method
1196
+ p
695
1197
  9
696
1198
  I
1199
+ 2
1200
+ I
697
1201
  d
698
1202
  I
699
- b
1203
+ 10
700
1204
  I
701
- 1b
1205
+ 16
702
1206
  I
703
- f
1207
+ 1e
704
1208
  I
705
- 29
1209
+ 23
706
1210
  I
707
- 16
1211
+ 28
708
1212
  I
709
- 37
1213
+ 26
1214
+ I
1215
+ 43
710
1216
  x
711
1217
  49
712
1218
  /Users/tony/src/celluloid/lib/celluloid/future.rb
@@ -717,11 +1223,11 @@ p
717
1223
  I
718
1224
  2
719
1225
  I
720
- 2
1226
+ 6
721
1227
  I
722
1228
  d
723
1229
  I
724
- 8
1230
+ c
725
1231
  I
726
1232
  28
727
1233
  x
@@ -733,13 +1239,17 @@ x
733
1239
  13
734
1240
  attach_method
735
1241
  p
736
- 3
1242
+ 5
737
1243
  I
738
1244
  0
739
1245
  I
740
1246
  1
741
1247
  I
742
- 1c
1248
+ 9
1249
+ I
1250
+ 3
1251
+ I
1252
+ 25
743
1253
  x
744
1254
  49
745
1255
  /Users/tony/src/celluloid/lib/celluloid/future.rb