Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
Alexandra Rogova
jio
Commits
d4e4af04
Commit
d4e4af04
authored
Apr 09, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replicate return first fulfilled instead of last
parent
7999c878
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
33 deletions
+68
-33
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+68
-33
No files found.
src/jio.storage/replicatestorage.js
View file @
d4e4af04
...
@@ -257,6 +257,52 @@
...
@@ -257,6 +257,52 @@
});
});
}
}
/**
* firstFulfilled(promises): promises< last_fulfilment_value >
*
* Responds with the first resolved promise answer recieved. If all promises
* are rejected, it returns the latest rejected promise answer
* received. Promises are cancelled only by calling
* `firstFulfilled(promises).cancel()`.
*
* @param {Array} promises An array of promises
* @return {Promise} A new promise
*/
function
firstFulfilled
(
promises
)
{
var
length
=
promises
.
length
;
function
onCancel
()
{
var
i
,
l
,
promise
;
for
(
i
=
0
,
l
=
promises
.
length
;
i
<
l
;
i
+=
1
)
{
promise
=
promises
[
i
];
if
(
typeof
promise
.
cancel
===
"
function
"
)
{
promise
.
cancel
();
}
}
}
return
new
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
i
,
count
=
0
;
function
resolver
(
answer
)
{
resolve
(
answer
);
onCancel
();
}
function
rejecter
(
answer
)
{
count
+=
1
;
if
(
count
===
length
)
{
return
reject
(
answer
);
}
}
for
(
i
=
0
;
i
<
length
;
i
+=
1
)
{
promises
[
i
].
then
(
resolver
,
rejecter
,
notify
);
}
},
onCancel
);
}
// //////////////////////////////////////////////////////////////////////
// /**
// /**
// * An Universal Unique ID generator
// * An Universal Unique ID generator
// *
// *
...
@@ -349,13 +395,11 @@
...
@@ -349,13 +395,11 @@
// return;
// return;
// }
// }
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
]
=
success
(
promise_list
[
index
]
=
command
.
storage
(
this
.
_storage_list
[
index
]).
post
(
metadata
,
option
)
command
.
storage
(
this
.
_storage_list
[
index
]).
post
(
metadata
,
option
);
);
}
}
sequence
([
function
()
{
firstFulfilled
(
promise_list
).
return
last
(
promise_list
);
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
},
[
command
.
success
,
command
.
error
]]);
};
};
ReplicateStorage
.
prototype
.
put
=
function
(
command
,
metadata
,
option
)
{
ReplicateStorage
.
prototype
.
put
=
function
(
command
,
metadata
,
option
)
{
...
@@ -372,33 +416,28 @@
...
@@ -372,33 +416,28 @@
promise_list
[
index
]
=
promise_list
[
index
]
=
command
.
storage
(
this
.
_storage_list
[
index
]).
put
(
metadata
,
option
);
command
.
storage
(
this
.
_storage_list
[
index
]).
put
(
metadata
,
option
);
}
}
sequence
([
function
()
{
firstFulfilled
(
promise_list
).
return
last
(
promise_list
);
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
},
[
command
.
success
,
command
.
error
]]);
};
};
ReplicateStorage
.
prototype
.
putAttachment
=
function
(
command
,
param
,
option
)
{
ReplicateStorage
.
prototype
.
putAttachment
=
function
(
command
,
param
,
option
)
{
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
]
=
success
(
promise_list
[
index
]
=
command
.
storage
(
this
.
_storage_list
[
index
]).
putAttachment
(
param
,
option
)
command
.
storage
(
this
.
_storage_list
[
index
]).
putAttachment
(
param
,
option
);
);
}
}
sequence
([
function
()
{
firstFulfilled
(
promise_list
).
return
last
(
promise_list
);
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
},
[
command
.
success
,
command
.
error
]]);
};
};
ReplicateStorage
.
prototype
.
remove
=
function
(
command
,
param
,
option
)
{
ReplicateStorage
.
prototype
.
remove
=
function
(
command
,
param
,
option
)
{
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
]
=
success
(
promise_list
[
index
]
=
command
.
storage
(
this
.
_storage_list
[
index
]).
remove
(
param
,
option
)
command
.
storage
(
this
.
_storage_list
[
index
]).
remove
(
param
,
option
);
);
}
}
sequence
([
function
()
{
firstFulfilled
(
promise_list
).
return
last
(
promise_list
);
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
},
[
command
.
success
,
command
.
error
]]);
};
};
ReplicateStorage
.
prototype
.
removeAttachment
=
function
(
ReplicateStorage
.
prototype
.
removeAttachment
=
function
(
...
@@ -408,14 +447,12 @@
...
@@ -408,14 +447,12 @@
)
{
)
{
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
]
=
success
(
promise_list
[
index
]
=
command
.
storage
(
this
.
_storage_list
[
index
]).
command
.
storage
(
this
.
_storage_list
[
index
]).
removeAttachment
(
param
,
option
)
removeAttachment
(
param
,
option
);
);
}
}
sequence
([
function
()
{
firstFulfilled
(
promise_list
).
return
last
(
promise_list
);
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
},
[
command
.
success
,
command
.
error
]]);
};
};
/**
/**
...
@@ -476,13 +513,11 @@
...
@@ -476,13 +513,11 @@
ReplicateStorage
.
prototype
.
getAttachment
=
function
(
command
,
param
,
option
)
{
ReplicateStorage
.
prototype
.
getAttachment
=
function
(
command
,
param
,
option
)
{
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
var
promise_list
=
[],
index
,
length
=
this
.
_storage_list
.
length
;
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
]
=
success
(
promise_list
[
index
]
=
command
.
storage
(
this
.
_storage_list
[
index
]).
getAttachment
(
param
,
option
)
command
.
storage
(
this
.
_storage_list
[
index
]).
getAttachment
(
param
,
option
);
);
}
}
sequence
([
function
()
{
firstFulfilled
(
promise_list
).
return
last
(
promise_list
);
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
},
[
command
.
success
,
command
.
error
]]);
};
};
ReplicateStorage
.
prototype
.
allDocs
=
function
(
command
,
param
,
option
)
{
ReplicateStorage
.
prototype
.
allDocs
=
function
(
command
,
param
,
option
)
{
...
...
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