Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
opening-hours
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
regionalkauf
opening-hours
Commits
a32fa7e1
Commit
a32fa7e1
authored
Jul 11, 2014
by
Johannes Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added Mocha Test
parent
9b2e6653
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
simplQueue.js
simplQueue.js
+52
-0
No files found.
simplQueue.js
0 → 100644
View file @
a32fa7e1
function
SimplQueue
(
finisher
)
{
this
.
_finisher
=
finisher
;
this
.
_queue
=
[];
this
.
_started
=
false
;
}
SimplQueue
.
prototype
.
push
=
function
(
cb
)
{
this
.
_queue
.
push
(
cb
);
if
(
this
.
_finisher
&&
!
this
.
_started
)
{
this
.
_started
=
true
;
var
next
=
this
.
_queue
.
shift
();
next
(
this
.
_handler
.
bind
(
this
));
}
};
SimplQueue
.
prototype
.
start
=
function
()
{
if
(
this
.
_started
)
return
;
this
.
_started
=
true
;
var
next
=
this
.
_queue
.
shift
();
if
(
next
)
next
(
this
.
_handler
.
bind
(
this
));
else
this
.
_finisher
();
};
SimplQueue
.
prototype
.
_handler
=
function
(
err
)
{
if
(
err
)
return
this
.
_finisher
(
err
);
var
next
=
this
.
_queue
.
shift
();
if
(
next
)
{
next
(
this
.
_handler
.
bind
(
this
));
}
else
this
.
_finisher
(
null
);
};
module
.
exports
=
SimplQueue
;
function
doStuff
()
{
var
queue
=
new
SimplQueue
(
function
(
err
)
{
console
.
log
(
err
);
console
.
log
(
"finished"
);
});
for
(
var
i
=
0
;
i
<
100
;
i
++
)
{
queue
.
push
(
function
(
cb
)
{
setTimeout
(
function
()
{
if
(
Math
.
random
()
>
0.9
)
return
cb
(
new
Error
(
"muh"
));
console
.
log
(
+
new
Date
());
cb
(
null
);
},
50
)
})
}
}
doStuff
();
\ No newline at end of file
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