I have this annoying warning and I'm not able to get rid of it.
Let's say that I have a promise that sends a command to a bluetooth le device, to do a procedure I need to send these commands synchronously.
So what you can do in PromiseKit 6 is create a for loop and append each command using a then to the previous promise. The issue with that approach is that the compiler trigger a warning about an Result of call to 'then(on:flags:_:)' is unused
, is like is missing the catch
. I'm aware that I can use a cauterize()
, but in this case I guess I will lost errors thrown while executing each promise. A when
is not viable because it will execute concurrently while I need synchronously.
Here a small sample used with strings, in my real application they are NOT string.
static func promise_startProcedure(with commands: [String]) -> Promise<Void> {
let promise = Promise()
for command in commands {
promise.then { //<-- WARNING SHOW HERE
Promise.value(command)
}
}
return promise
}
Is there a way to get rid of this warning?
[UPDATE]
I did a mistake, the answer was not correct bu pointed me to the right direction.
static func promise_startProcedure(with commands: [String]) -> Promise<Void> {
var promise = Promise()
for command in commands {
promise = promise.then {
Promise.value(command)
}
}
return promise
}
Try this. I just added Underscore
to suppress the warning and did not get that warning.
static func promise_startProcedure(with commands: [String]) -> Promise<Void> {
let promise = Promise()
for command in commands {
_ = promise.then {
Promise.value(command)
}
}
return promise
}