Skip to content

Instantly share code, notes, and snippets.

@terjesb
Forked from hlship/feed.clj
Created November 26, 2016 17:01
Show Gist options
  • Select an option

  • Save terjesb/58d9da26aeca4fcb8b6378216355513c to your computer and use it in GitHub Desktop.

Select an option

Save terjesb/58d9da26aeca4fcb8b6378216355513c to your computer and use it in GitHub Desktop.

Revisions

  1. @hlship hlship revised this gist Jul 24, 2014. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions feed.clj
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,7 @@
    (-> (onto-chan payment-code-feed
    (->>
    (range block-start (+ block-start payment-codes-per-block))
    (map sa/int->six-alpha)
    (remove sa/is-banned?))
    (map sa/int->six-alpha))
    ;; Don't close!
    false)
    ;; park here until all of that block has been consumed.
  2. @hlship hlship created this gist Jul 24, 2014.
    20 changes: 20 additions & 0 deletions feed.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    (def payment-codes-per-block 4096)

    (defn create-payment-code-feed
    [db]
    (let [payment-code-feed (chan 10)]
    (go-loop []
    (let [block-id (allocate-block db)
    block-start (* block-id payment-codes-per-block)]
    (-> (onto-chan payment-code-feed
    (->>
    (range block-start (+ block-start payment-codes-per-block))
    (map sa/int->six-alpha)
    (remove sa/is-banned?))
    ;; Don't close!
    false)
    ;; park here until all of that block has been consumed.
    <!))
    ;; Loop forever.
    (recur))
    payment-code-feed))