@@ -147,56 +147,33 @@ IPFS.createNode = (options) => {
147147/**
148148 * Static factory method to create a node wrapped with a Promise
149149 *
150- * The Promise does *NOT* wait for the Ready Event to resolve with a IPFS instance
151- * and rejects with Error Events.
152- *
153- * @param {object } options
154- * @returns {IPFS }
155- */
156- IPFS . createNodePromise = ( options ) => {
157- return new Promise ( ( resolve , reject ) => {
158- const node = new IPFS ( options )
159-
160- node . on ( 'error' , err => {
161- reject ( err )
162- } )
163-
164- resolve ( node )
165- } )
166- }
167-
168- /**
169- * Static factory method to create a ready node wrapped with a Promise
170- *
171150 * The Promise waits for the Ready Event to resolve with a IPFS instance
172- * and rejects with Error Events or a repo not initialized.
151+ * and rejects with Error Events. Rejections can be customized the with
152+ * second param.
173153 *
174- * @param {Object } options IPFS constructor options
154+ * @param {object } options - IPFS node options
155+ * @param {object } stateOptions - Node state options to reject with error
175156 * @returns {IPFS }
176157 */
177- IPFS . createReadyNodePromise = ( options = { } ) => {
158+ IPFS . createNodePromise = ( options = { } , stateOptions = { } ) => {
178159 return new Promise ( ( resolve , reject ) => {
179160 const node = new IPFS ( options )
180161
181- node . once ( 'error' , err => {
162+ node . on ( 'error' , err => {
182163 reject ( err )
183164 } )
184165
185166 node . once ( 'ready' , ( ) => {
186- /**
187- * We shouldn't need to do this but until we get a unified error from ipfs-repo
188- * we catch it here
189- */
190- node . _repo . _isInitialized ( ( err ) => {
191- if ( err ) {
192- reject ( Object . assign ( new Error ( 'repo is not initialized yet' ) ,
193- {
194- code : 'ERR_REPO_NOT_INITIALIZED' ,
195- path : node . _repo . path
196- } ) )
197- }
167+ if ( stateOptions . forceInitialized ) {
168+ node . _repo . _isInitialized ( ( err ) => {
169+ if ( err ) {
170+ reject ( err )
171+ }
172+ resolve ( node )
173+ } )
174+ } else {
198175 resolve ( node )
199- } )
176+ }
200177 } )
201178 } )
202179}
0 commit comments