Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Vincent Bechu
jio
Commits
92781fb2
Commit
92781fb2
authored
Apr 29, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replicate synchronizes all storages
parent
34ecf915
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
1 deletion
+60
-1
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+60
-1
No files found.
src/jio.storage/replicatestorage.js
View file @
92781fb2
...
@@ -202,7 +202,7 @@
...
@@ -202,7 +202,7 @@
function
next
()
{
function
next
()
{
if
(
array
.
length
)
{
if
(
array
.
length
)
{
try
{
try
{
value
=
callback
.
call
(
null
,
array
.
shift
(),
array
);
value
=
callback
(
array
.
shift
(),
array
);
}
catch
(
e
)
{
}
catch
(
e
)
{
return
fail
(
e
);
return
fail
(
e
);
}
}
...
@@ -225,6 +225,35 @@
...
@@ -225,6 +225,35 @@
});
});
}
}
function
doWhile
(
callback
)
{
var
cancelled
,
p1
=
resolve
(),
p2
;
return
new
Promise
(
function
(
done
,
fail
,
notify
)
{
function
next
(
value
)
{
if
(
value
)
{
try
{
value
=
callback
();
}
catch
(
e
)
{
return
fail
(
e
);
}
if
(
cancelled
)
{
return
;
}
if
(
value
&&
typeof
value
.
then
===
"
function
"
)
{
p1
=
value
;
p2
=
value
.
then
(
next
,
fail
,
notify
);
}
else
{
p2
=
p2
.
then
(
next
.
bind
(
null
,
value
),
fail
,
notify
);
}
return
;
}
done
();
}
p2
=
p1
.
then
(
next
.
bind
(
null
,
true
));
},
function
()
{
cancelled
=
true
;
if
(
typeof
p1
.
cancel
===
"
function
"
)
{
p1
.
cancel
();
}
if
(
typeof
p2
.
cancel
===
"
function
"
)
{
p2
.
cancel
();
}
});
}
// //////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////
// /**
// /**
...
@@ -309,6 +338,13 @@
...
@@ -309,6 +338,13 @@
if
(
typeof
spec
.
cache_storage
===
"
object
"
&&
spec
.
cache_storage
!==
null
)
{
if
(
typeof
spec
.
cache_storage
===
"
object
"
&&
spec
.
cache_storage
!==
null
)
{
this
.
_cache_storage
=
spec
.
cache_storage
;
this
.
_cache_storage
=
spec
.
cache_storage
;
}
}
if
(
typeof
spec
.
batch_length
===
"
number
"
&&
isFinite
(
spec
.
batch_length
)
&&
spec
.
batch_length
>
0
)
{
this
.
_batch_length
=
spec
.
batch_length
;
}
else
{
this
.
_batch_length
=
10
;
}
this
.
_cache
.
batch_index
=
this
.
_cache
.
batch_index
||
0
;
}
}
ReplicateStorage
.
prototype
.
syncRowFIFO
=
function
(
command
)
{
ReplicateStorage
.
prototype
.
syncRowFIFO
=
function
(
command
)
{
...
@@ -412,6 +448,29 @@
...
@@ -412,6 +448,29 @@
});
});
});
});
p
.
then
(
deleteCache
,
deleteCache
);
p
.
then
(
deleteCache
,
deleteCache
);
if
(
this
.
_cache
.
batch_index
===
0
)
{
// no global synchronisation is on going
p
.
then
(
function
()
{
return
doWhile
(
function
()
{
var
i
=
it
.
_cache
.
batch_index
,
l
=
it
.
_batch_length
,
test
=
true
;
it
.
_cache
.
batch_index
+=
1
;
return
it
.
_allDocs
(
command
,
{},
{
"
limit
"
:
[
i
*
l
,
l
]
}).
then
(
function
(
answer
)
{
if
(
answer
.
data
.
total_rows
<
l
)
{
test
=
false
;
}
return
it
.
_cache
.
syncRowFIFO
;
}).
then
(
function
()
{
return
test
;
});
});
}).
then
(
null
,
function
()
{
return
;
}).
then
(
function
()
{
it
.
_cache
.
batch_index
=
0
;
});
}
this
.
_cache
.
syncRowFIFO
=
p
;
this
.
_cache
.
syncRowFIFO
=
p
;
return
p
;
return
p
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment