Commit 05823d6d7c289c51a49c2d0eb8911e4df09bdfca
UGLY HACK so that sbot_blobs_add calls back after write has succeeded
Dominic Tarr committed on 7/24/2016, 1:08:39 AMParent: f472c56537886044c04798db5a6d9b631285d1ac
Files changed
sbot-api.js | changed |
sbot-api.js | ||
---|---|---|
@@ -68,9 +68,22 @@ | ||
68 | 68 | |
69 | 69 | return { |
70 | 70 | sbot_blobs_add: rec.sink(function (cb) { |
71 | 71 | return pull( |
72 | - Hash(cb), | |
72 | + Hash(function (err, id) { | |
73 | + if(err) return cb(err) | |
74 | + //completely UGLY hack to tell when the blob has been sucessfully written... | |
75 | + var start = Date.now(), n = 5 | |
76 | + ;(function next () { | |
77 | + setTimeout(function () { | |
78 | + sbot.blobs.has(id, function (err, has) { | |
79 | + if(has) return cb(null, id) | |
80 | + if(n--) next() | |
81 | + else cb(new Error('write failed')) | |
82 | + }) | |
83 | + }, Date.now() - start) | |
84 | + })() | |
85 | + }), | |
73 | 86 | sbot.blobs.add() |
74 | 87 | ) |
75 | 88 | }), |
76 | 89 | sbot_links: rec.source(function (query) { |
@@ -108,4 +121,6 @@ | ||
108 | 121 | }) |
109 | 122 | } |
110 | 123 | } |
111 | 124 | |
125 | + | |
126 | + |
Built with git-ssb-web