Skip to content
This repository
Browse code

cleanup old code

  • Loading branch information...
commit c84ef8c975bfaa4ee9be2f8172e7ac42294a40b2 1 parent 4ee8d83
Christopher Bertels authored

Showing 3 changed files with 0 additions and 144 deletions. Show diff stats Hide diff stats

  1. +0 1  lib/boot.fy
  2. +0 41 lib/future.fy
  3. +0 102 lib/thread_pool.fy
1  lib/boot.fy
@@ -36,7 +36,6 @@ require: "set"
36 36 require: "symbol"
37 37 require: "stack"
38 38 require: "proxy"
39   -require: "thread_pool"
40 39 require: "fiber"
41 40 require: "future"
42 41 require: "struct"
41 lib/future.fy
@@ -185,47 +185,6 @@ class FutureSend {
185 185 }
186 186 }
187 187
188   -class PooledFuture {
189   - @@thread_pool = nil
190   - @@pool_size = 10
191   - WaitInterval = 0.1
192   -
193   - def PooledFuture pool: n {
194   - @@pool_size = match n {
195   - case 0 -> 10
196   - case _ -> n
197   - }
198   - }
199   -
200   - def PooledFuture join! {
201   - @@thread_pool join
202   - }
203   -
204   - def initialize: @block {
205   - { @@thread_pool = ThreadPool new: @@pool_size } unless: @@thread_pool
206   - @@thread_pool execute: @block
207   - }
208   -
209   - def when_done: block {
210   - PooledFuture new: {
211   - block call: [value]
212   - }
213   - }
214   -
215   - def && block {
216   - when_done: block
217   - }
218   -
219   - def completed? {
220   - @block complete?
221   - }
222   -
223   - def value {
224   - { Thread sleep: WaitInterval } until: { completed? }
225   - @block completed_value
226   - }
227   -}
228   -
229 188 class FutureCollection {
230 189 include: Fancy Enumerable
231 190
102 lib/thread_pool.fy
... ... @@ -1,102 +0,0 @@
1   -# This ThreadPool class is adapted from the Ruby code at:
2   -# https://github.com/fizx/thread_pool/
3   -
4   -class ThreadPool {
5   - class Executor {
6   - read_slot: 'active
7   -
8   - def initialize: queue mutex: mutex {
9   - @thread = Thread new: {
10   - loop: {
11   - mutex synchronize() { @tuple = queue shift() }
12   - if: @tuple then: {
13   - args, block = @tuple
14   - @active = true
15   - val = nil
16   - try {
17   - val = block call: args
18   - } catch StandardError => e {
19   - e message println
20   - e backtrace() join: "\n" . println
21   - }
22   - block complete: true
23   - block completed_value: val
24   - } else: {
25   - @active = false
26   - Thread sleep: 0.1
27   - }
28   - }
29   - }
30   - }
31   -
32   - def close {
33   - @thread exit
34   - }
35   - }
36   -
37   - read_write_slot: 'queue_limit
38   -
39   - # Initialize with number of threads to run
40   - def initialize: @count limit: @queue_limit (0) {
41   - @mutex = Mutex new()
42   - @executors = []
43   - @queue = []
44   - @count times: { @executors << (Executor new: @queue mutex: @mutex) }
45   - }
46   -
47   - # Runs the block at some time in the near future
48   - def execute: block with_args: args ([]) {
49   - init_completable: block
50   -
51   - if: (@queue_limit > 0) then: {
52   - { Thread sleep: 0.1 } until: { @queue size < @queue_limit }
53   - }
54   -
55   - @mutex synchronize() {
56   - @queue << [args, block]
57   - }
58   - }
59   -
60   - # Runs the block at some time in the near future, and blocks until complete
61   - def execute_synchronous: block with_args: args ([]) {
62   - execute: block with_args: args
63   - { Thread sleep: 0.1 } until: { block complete? }
64   - block completed_value
65   - }
66   -
67   - # Size of the task queue
68   - def waiting {
69   - @queue size
70   - }
71   -
72   - # Size of the thread pool
73   - def size {
74   - @count
75   - }
76   -
77   - # Kills all threads
78   - def close {
79   - @executors each: @{ close }
80   - }
81   -
82   - # Sleeps and blocks until the task queue is finished executing
83   - def join {
84   - { Thread sleep: 0.1 } until: { { @queue empty? } && { @executors all?: @{ active not } } }
85   - }
86   -
87   - class Completable {
88   - read_write_slot: 'completed_value
89   - def complete: @complete {
90   - }
91   -
92   - def complete? {
93   - @complete not not
94   - }
95   - }
96   -
97   - def init_completable: block {
98   - block extend(Completable)
99   - block complete: false
100   - }
101   - protected: 'init_completable:
102   -}

0 comments on commit c84ef8c

Please sign in to comment.
Something went wrong with that request. Please try again.