https://kotlinlang.org logo
Title
w

wcaokaze

05/30/2018, 10:15 AM
Can we get a Job that is already completed?
a

alex.krupa

05/30/2018, 10:34 AM
What do you mean? Are you asking if we can still use a completed Job?
w

wcaokaze

05/30/2018, 10:37 AM
Oh sorry for ambiguous. I meant like the follow
val job = // some way
assert(job.isCompleted)
l

louiscad

05/30/2018, 10:43 AM
@wcaokaze Still unclear what you want to do, your code doesn't make sense in regards to what you told first
w

wcaokaze

05/30/2018, 10:50 AM
For example, I want to make a button to download some data.
private var fetchingJob: Job

fun onButtonClicked() {
   if (!fetchingJob.isCompleted) return

   fetchingJob = launch (UI) {
      // ...
   }
}
How can I initialize
fetchingJob
in constructor?
null
makes it complicated
l

louiscad

05/30/2018, 11:02 AM
I still don't understand what you're trying to do @wcaokaze
a

alex.krupa

05/30/2018, 11:03 AM
private var fetchingJob: Job? = null

fun onButtonClicked() {
    if (!fetchingJob?.isCompleted == true) return

    fetchingJob = launch(UI) { ... }
}
Do you mean something like this?
w

wcaokaze

05/30/2018, 11:46 AM
Yep, currently I use it.
And what I want to do is
private var fetchingJob: Job = Job.completed

fun onButtonClicked() {
   if (!fetchingJob.isCompleted) return

   fetchingJob = launch (UI) { ... }
}
l

louiscad

05/30/2018, 12:51 PM
@wcaokaze Could you explain in English what you're trying to do? My mental compiler has bugs and inference to what you're trying to do exactly doesn't work
g

gildor

05/30/2018, 1:33 PM
As I understand you are trying to create Job instance that already completed, with isCompleted=true by default. There is no such implementation now, you can write your own (job is just an interface), but I would just use
null
as default value
😒imple_smile: 1
w

wcaokaze

05/30/2018, 1:56 PM
@gildor Thanks!!