braidfs 0.0.93 → 0.0.94
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.
- package/index.js +50 -17
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -717,7 +717,7 @@ async function sync_url(url) {
|
|
|
717
717
|
await write_meta_file()
|
|
718
718
|
if (freed) return
|
|
719
719
|
|
|
720
|
-
if (await wait_on(is_read_only(fullpath) !== self.file_read_only)
|
|
720
|
+
if (await wait_on(is_read_only(fullpath)) !== self.file_read_only) {
|
|
721
721
|
if (freed) return
|
|
722
722
|
self.file_ignore_until = Date.now() + 1000
|
|
723
723
|
await wait_on(set_read_only(fullpath, self.file_read_only))
|
|
@@ -889,7 +889,6 @@ async function sync_url(url) {
|
|
|
889
889
|
if (update.version.length !== 1) throw 'unexpected'
|
|
890
890
|
|
|
891
891
|
await wait_on(braid_text.put(url, { ...update, peer: self.peer, merge_type: 'dt' }))
|
|
892
|
-
console.log(`PUT DONE!`)
|
|
893
892
|
if (freed) return
|
|
894
893
|
|
|
895
894
|
// the server is giving us this version,
|
|
@@ -904,8 +903,52 @@ async function sync_url(url) {
|
|
|
904
903
|
|
|
905
904
|
// send it stuff we have but it doesn't't
|
|
906
905
|
async function send_new_stuff(fork_point) {
|
|
907
|
-
if (freed) return
|
|
908
|
-
var
|
|
906
|
+
if (freed) return
|
|
907
|
+
var q = []
|
|
908
|
+
var in_flight = new Map()
|
|
909
|
+
var max_in_flight = 10
|
|
910
|
+
var send_pump_lock = 0
|
|
911
|
+
|
|
912
|
+
async function send_pump() {
|
|
913
|
+
send_pump_lock++
|
|
914
|
+
if (send_pump_lock > 1) return
|
|
915
|
+
try {
|
|
916
|
+
if (freed) return
|
|
917
|
+
if (in_flight.size >= max_in_flight) return
|
|
918
|
+
if (!q.length) {
|
|
919
|
+
var frontier = self.fork_point
|
|
920
|
+
for (var u of in_flight.values())
|
|
921
|
+
frontier = extend_frontier(frontier, u.version[0], u.parents)
|
|
922
|
+
|
|
923
|
+
var options = {
|
|
924
|
+
parents: frontier,
|
|
925
|
+
merge_type: 'dt',
|
|
926
|
+
peer: self.peer,
|
|
927
|
+
subscribe: u => u.version.length && q.push(u)
|
|
928
|
+
}
|
|
929
|
+
await braid_text.get(url, options)
|
|
930
|
+
await braid_text.forget(url, options)
|
|
931
|
+
}
|
|
932
|
+
while (q.length && in_flight.size < max_in_flight) {
|
|
933
|
+
let u = q.shift()
|
|
934
|
+
in_flight.set(u.version[0], u);
|
|
935
|
+
(async () => {
|
|
936
|
+
await initial_connect_promise
|
|
937
|
+
if (freed) return
|
|
938
|
+
await send_out({...u, peer: self.peer})
|
|
939
|
+
if (freed) return
|
|
940
|
+
in_flight.delete(u.version[0])
|
|
941
|
+
setTimeout(send_pump, 0)
|
|
942
|
+
})()
|
|
943
|
+
}
|
|
944
|
+
} finally {
|
|
945
|
+
var retry = send_pump_lock > 1
|
|
946
|
+
send_pump_lock = 0
|
|
947
|
+
if (retry) setTimeout(send_pump, 0)
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
var initial_stuff = true
|
|
909
952
|
await wait_on(braid_text.get(url, braid_text_get_options = {
|
|
910
953
|
parents: fork_point,
|
|
911
954
|
merge_type: 'dt',
|
|
@@ -914,11 +957,12 @@ async function sync_url(url) {
|
|
|
914
957
|
if (freed) return
|
|
915
958
|
if (u.version.length) {
|
|
916
959
|
self.signal_file_needs_writing()
|
|
917
|
-
|
|
918
|
-
|
|
960
|
+
if (initial_stuff || in_flight.size < max_in_flight) q.push(u)
|
|
961
|
+
send_pump()
|
|
919
962
|
}
|
|
920
963
|
},
|
|
921
964
|
}))
|
|
965
|
+
initial_stuff = false
|
|
922
966
|
}
|
|
923
967
|
|
|
924
968
|
// for config and errors file, listen for web changes
|
|
@@ -1098,14 +1142,3 @@ async function file_exists(fullpath) {
|
|
|
1098
1142
|
function sha256(x) {
|
|
1099
1143
|
return require('crypto').createHash('sha256').update(x).digest('base64')
|
|
1100
1144
|
}
|
|
1101
|
-
|
|
1102
|
-
function create_parallel_promises(N) {
|
|
1103
|
-
var q = []
|
|
1104
|
-
var n = 0
|
|
1105
|
-
return async f => {
|
|
1106
|
-
q.push(f)
|
|
1107
|
-
n++
|
|
1108
|
-
while (q.length && n <= N) await q.shift()()
|
|
1109
|
-
n--
|
|
1110
|
-
}
|
|
1111
|
-
}
|