@@ -487,38 +487,46 @@ _.extend(Eventstore.prototype, {
487487 currentRevision = eventstream . currentRevision ( ) ,
488488 uncommittedEvents = [ ] . concat ( eventstream . uncommittedEvents ) ;
489489 eventstream . uncommittedEvents = [ ] ;
490- for ( var i = 0 , len = uncommittedEvents . length ; i < len ; i ++ ) {
491- event = uncommittedEvents [ i ] ;
492- event . id = id + i . toString ( ) ;
493- event . commitId = id ;
494- event . commitSequence = i ;
495- event . restInCommitStream = len - 1 - i ;
496- event . commitStamp = new Date ( ) ;
497- currentRevision ++ ;
498- event . streamRevision = currentRevision ;
499-
500- event . applyMappings ( ) ;
501- }
502490
503- self . store . addEvents ( uncommittedEvents , function ( err ) {
504- if ( err ) {
505- // add uncommitted events back to eventstream
506- eventstream . uncommittedEvents = uncommittedEvents . concat ( eventstream . uncommittedEvents ) ;
507- return callback ( err ) ;
491+ self . store . getNextPositions ( uncommittedEvents . length , function ( err , positions ) {
492+ if ( err )
493+ return callback ( err )
494+
495+ for ( var i = 0 , len = uncommittedEvents . length ; i < len ; i ++ ) {
496+ event = uncommittedEvents [ i ] ;
497+ event . id = id + i . toString ( ) ;
498+ event . commitId = id ;
499+ event . commitSequence = i ;
500+ event . restInCommitStream = len - 1 - i ;
501+ event . commitStamp = new Date ( ) ;
502+ currentRevision ++ ;
503+ event . streamRevision = currentRevision ;
504+ if ( positions )
505+ event . position = positions [ i ] ;
506+
507+ event . applyMappings ( ) ;
508508 }
509509
510- if ( self . publisher && self . dispatcher ) {
511- // push to undispatchedQueue
512- self . dispatcher . addUndispatchedEvents ( uncommittedEvents ) ;
513- } else {
514- eventstream . eventsToDispatch = [ ] . concat ( uncommittedEvents ) ;
515- }
510+ self . store . addEvents ( uncommittedEvents , function ( err ) {
511+ if ( err ) {
512+ // add uncommitted events back to eventstream
513+ eventstream . uncommittedEvents = uncommittedEvents . concat ( eventstream . uncommittedEvents ) ;
514+ return callback ( err ) ;
515+ }
516516
517- // move uncommitted events to events
518- eventstream . events = eventstream . events . concat ( uncommittedEvents ) ;
519- eventstream . currentRevision ( ) ;
517+ if ( self . publisher && self . dispatcher ) {
518+ // push to undispatchedQueue
519+ self . dispatcher . addUndispatchedEvents ( uncommittedEvents ) ;
520+ } else {
521+ eventstream . eventsToDispatch = [ ] . concat ( uncommittedEvents ) ;
522+ }
520523
521- callback ( null , eventstream ) ;
524+ // move uncommitted events to events
525+ eventstream . events = eventstream . events . concat ( uncommittedEvents ) ;
526+ eventstream . currentRevision ( ) ;
527+
528+ callback ( null , eventstream ) ;
529+ } ) ;
522530 } ) ;
523531 } ] ,
524532
0 commit comments