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
Yaxel Perez
jio
Commits
86970117
Commit
86970117
authored
Jun 14, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce number of created Queue.
Reuse Queue created from callback directly.
parent
7f5c500e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
77 deletions
+86
-77
src/jio.js
src/jio.js
+86
-77
No files found.
src/jio.js
View file @
86970117
...
...
@@ -209,47 +209,64 @@
}
}
function
ensurePushableQueue
(
callback
,
argument_list
,
context
)
{
var
result
;
try
{
result
=
callback
.
apply
(
context
,
argument_list
);
}
catch
(
e
)
{
return
new
RSVP
.
Queue
()
.
push
(
function
returnPushableError
()
{
return
RSVP
.
reject
(
e
);
});
}
if
(
result
instanceof
RSVP
.
Queue
)
{
return
result
;
}
return
new
RSVP
.
Queue
()
.
push
(
function
returnPushableResult
()
{
return
result
;
});
}
function
declareMethod
(
klass
,
name
,
precondition_function
,
post_function
)
{
klass
.
prototype
[
name
]
=
function
()
{
var
argument_list
=
arguments
,
context
=
this
,
precondition_result
;
precondition_result
,
storage_method
,
queue
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
precondition_function
!==
undefined
)
{
return
precondition_function
.
apply
(
context
.
__storage
,
[
argument_list
,
context
,
name
]
);
}
})
.
push
(
function
(
result
)
{
var
storage_method
=
context
.
__storage
[
name
];
precondition_result
=
result
;
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
);
}
return
storage_method
.
apply
(
context
.
__storage
,
argument_list
);
})
.
push
(
function
(
result
)
{
if
(
post_function
!==
undefined
)
{
// Precondition function are not asynchronous
if
(
precondition_function
!==
undefined
)
{
precondition_result
=
precondition_function
.
apply
(
context
.
__storage
,
[
argument_list
,
context
,
name
]
);
}
storage_method
=
context
.
__storage
[
name
];
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity '
"
+
name
+
"
' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
);
}
queue
=
ensurePushableQueue
(
storage_method
,
argument_list
,
context
.
__storage
);
if
(
post_function
!==
undefined
)
{
queue
.
push
(
function
(
result
)
{
return
post_function
.
call
(
context
,
argument_list
,
result
,
precondition_result
);
}
return
result
;
})
;
}
);
}
return
queue
;
};
// Allow chain
return
this
;
...
...
@@ -281,17 +298,16 @@
JioProxyStorage
.
prototype
.
post
=
function
()
{
var
context
=
this
,
argument_list
=
arguments
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
storage_method
=
context
.
__storage
.
post
;
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity 'post' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
);
}
return
context
.
__storage
.
post
.
apply
(
context
.
__storage
,
argument_list
);
});
return
ensurePushableQueue
(
function
()
{
var
storage_method
=
context
.
__storage
.
post
;
if
(
storage_method
===
undefined
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Capacity 'post' is not implemented on '
"
+
context
.
__type
+
"
'
"
,
501
);
}
return
context
.
__storage
.
post
.
apply
(
context
.
__storage
,
argument_list
);
});
};
declareMethod
(
JioProxyStorage
,
'
putAttachment
'
,
function
(
argument_list
,
...
...
@@ -409,13 +425,8 @@
501
);
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
return
storage_method
.
apply
(
context
.
__storage
,
argument_list
);
});
return
ensurePushableQueue
(
storage_method
,
argument_list
,
context
.
__storage
);
};
JioProxyStorage
.
prototype
.
hasCapacity
=
function
(
name
)
{
...
...
@@ -439,27 +450,26 @@
if
(
options
===
undefined
)
{
options
=
{};
}
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
context
.
hasCapacity
(
"
list
"
)
&&
((
options
.
query
===
undefined
)
||
context
.
hasCapacity
(
"
query
"
))
&&
((
options
.
sort_on
===
undefined
)
||
context
.
hasCapacity
(
"
sort
"
))
&&
((
options
.
select_list
===
undefined
)
||
context
.
hasCapacity
(
"
select
"
))
&&
((
options
.
include_docs
===
undefined
)
||
context
.
hasCapacity
(
"
include
"
))
&&
((
options
.
limit
===
undefined
)
||
context
.
hasCapacity
(
"
limit
"
)))
{
return
context
.
buildQuery
(
options
);
}
})
.
push
(
function
(
result
)
{
return
{
data
:
{
rows
:
result
,
total_rows
:
result
.
length
}
};
});
return
ensurePushableQueue
(
function
()
{
if
(
context
.
hasCapacity
(
"
list
"
)
&&
((
options
.
query
===
undefined
)
||
context
.
hasCapacity
(
"
query
"
))
&&
((
options
.
sort_on
===
undefined
)
||
context
.
hasCapacity
(
"
sort
"
))
&&
((
options
.
select_list
===
undefined
)
||
context
.
hasCapacity
(
"
select
"
))
&&
((
options
.
include_docs
===
undefined
)
||
context
.
hasCapacity
(
"
include
"
))
&&
((
options
.
limit
===
undefined
)
||
context
.
hasCapacity
(
"
limit
"
)))
{
return
context
.
buildQuery
(
options
)
.
push
(
function
(
result
)
{
return
{
data
:
{
rows
:
result
,
total_rows
:
result
.
length
}
};
});
}
});
};
declareMethod
(
JioProxyStorage
,
"
allAttachments
"
,
checkId
);
...
...
@@ -468,14 +478,13 @@
JioProxyStorage
.
prototype
.
repair
=
function
()
{
var
context
=
this
,
argument_list
=
arguments
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
var
storage_method
=
context
.
__storage
.
repair
;
if
(
storage_method
!==
undefined
)
{
return
context
.
__storage
.
repair
.
apply
(
context
.
__storage
,
argument_list
);
}
});
return
ensurePushableQueue
(
function
()
{
var
storage_method
=
context
.
__storage
.
repair
;
if
(
storage_method
!==
undefined
)
{
return
context
.
__storage
.
repair
.
apply
(
context
.
__storage
,
argument_list
);
}
});
};
/////////////////////////////////////////////////////////////////
...
...
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