@@ -20,21 +20,29 @@ class tasks {
2020 }
2121
2222 /**
23- * Filter frames that need an update and resolve merge_requests and issues
24- * respectively.
23+ * Filter frames that need an update
2524 * @returns {Promise }
2625 */
27- syncResolve ( ) {
26+ syncInit ( ) {
2827 this . sync . frames = new FrameCollection ( this . config ) ;
2928
29+ // filter out frames, that don't need an update
30+ this . sync . frames . filter ( frame => ! ( Math . ceil ( frame . duration ) === _ . reduce ( frame . notes , ( n , m ) => ( n + m . time ) , 0 ) ) ) ;
31+
32+ return new Promise ( r => r ( ) ) ;
33+ }
34+
35+ /**
36+ * Resolve merge_requests and issues
37+ * respectively.
38+ * @returns {Promise }
39+ */
40+ syncResolve ( callback ) {
3041 this . sync . resources = {
3142 issue : { } ,
3243 merge_request : { }
3344 } ;
3445
35- // filter out frames, that don't need an update
36- this . sync . frames . filter ( frame => ! ( Math . ceil ( frame . duration ) === _ . reduce ( frame . notes , ( n , m ) => ( n + m . time ) , 0 ) ) ) ;
37-
3846 // resolve issues and merge requests
3947 return this . sync . frames . forEach ( ( frame , done ) => {
4048 let project = frame . project ,
@@ -48,26 +56,35 @@ class tasks {
4856 this . sync . resources [ type ] [ id ] = new classes [ type ] ( this . config , { } ) ;
4957 this . sync . resources [ type ] [ id ]
5058 . make ( project , id )
51- . then ( ( ) => done ( ) )
59+ . then ( ( ) => {
60+ if ( callback ) callback ( ) ;
61+ done ( ) ;
62+ } )
5263 . catch ( error => done ( `Could not resolve ${ type } ${ id } on "${ project } "` ) ) ;
5364 } )
5465 }
5566
5667 /**
5768 * Get notes for all frames.
5869 */
59- syncNotes ( ) {
70+ syncNotes ( callback ) {
6071 return this . sync . frames . forEach ( ( frame , done ) => {
6172 let project = frame . project ,
6273 type = frame . resource . type ,
6374 id = frame . resource . id ,
6475 notes ;
6576
66- if ( ( notes = this . sync . resources [ type ] [ id ] . notes ) && notes . length > 0 ) return ;
77+ if ( ( notes = this . sync . resources [ type ] [ id ] . notes ) && notes . length > 0 ) {
78+ if ( callback ) callback ( ) ;
79+ return done ( ) ;
80+ }
6781
6882 this . sync . resources [ type ] [ id ]
6983 . getNotes ( )
70- . then ( ( ) => done ( ) )
84+ . then ( ( ) => {
85+ if ( callback ) callback ( ) ;
86+ done ( ) ;
87+ } )
7188 . catch ( error => done ( `Could not get notes from ${ type } ${ id } on "${ project } "` ) ) ;
7289 } ) ;
7390 }
@@ -92,22 +109,24 @@ class tasks {
92109 }
93110
94111 _addTime ( frame , time ) {
95- return new Promise ( ( resolve , reject ) => {
112+ return new Promise ( async function ( resolve , reject ) {
96113 let resource = this . sync . resources [ frame . resource . type ] [ frame . resource . id ] ;
97114
98- resource
99- . createTime ( Math . ceil ( time ) )
100- . then ( ( ) => resource . getNotes ( ) )
101- . then ( ( ) => {
102- frame . notes . push ( {
103- id : resource . notes [ 0 ] . id ,
104- time : Math . ceil ( time )
105- } ) ;
106- frame . write ( ) ;
107- resolve ( ) ;
108- } )
109- . catch ( error => reject ( error ) )
110- } ) ;
115+ try {
116+ await resource . createTime ( Math . ceil ( time ) ) ;
117+ await resource . getNotes ( ) ;
118+ } catch ( error ) {
119+ return reject ( error ) ;
120+ }
121+
122+ frame . notes . push ( {
123+ id : resource . notes [ 0 ] . id ,
124+ time : Math . ceil ( time )
125+ } ) ;
126+
127+ frame . write ( ) ;
128+ resolve ( ) ;
129+ } . bind ( this ) ) ;
111130 }
112131
113132 /**
0 commit comments