import { delay } from 'redux-saga';
import { spawn, fork, join, call, cancel } from 'redux-saga/effects';

function func() {
  console.log(1.5);
}

function* generator(i) {
  yield call(delay, 1000);
  console.log(yield `-- ${i}`);
  yield call(childGenerator, i);
}

function* childGenerator(i) {
  yield call(delay, 2000);
  console.log(yield `---- ${i}`);
}

export default function* api() {
  console.log(yield 'call(func) -> {');
  yield call(func);
  console.log(yield '} <- call(func)');
  
  console.log(yield 'fork(generator) -> {');
  yield fork(generator, 'fork(generator)');
  console.log(yield '} <- fork(generator)');
  
  console.log('fork(generator) and join(task) -> {');
  let task = yield fork(generator, 'fork(generator) and join(task)');
  yield join(task);
  console.log(yield '} <- fork(generator) and join(task)');
  
  console.log('spawn(generator) -> {');
  yield spawn(generator, 'spawn(generator)');
  yield join(task);
  console.log(yield '} <- spawn(generator)');
  
  console.log('spawn(generator) and join(task) -> {');
  task = yield spawn(generator, 'spawn(generator) and join(task)');
  yield join(task);
  console.log(yield '} <- spawn(generator) and join(task)');
  
  console.log('fork(generator) and cancel(task) -> {');
  task = yield fork(generator, 'fork(generator) and cancel(task)');
  yield call(delay, 500)
  yield cancel(task);
  console.log(yield '} <- fork(generator) and cancel(task)');
  
}

@@ -232,22 +232,18 @@
 %0A  yield
+*
  
-call(
 childGen
@@ -248,18 +248,17 @@
 enerator
-, 
+(
 i);%0A%7D%0A%0Af
@@ -379,11 +379,24 @@
 on* 
-api
+nonBlockingCalls
 () %7B
@@ -1349,16 +1349,17 @@
 (delay, 
+1
 500)%0A  y
@@ -1442,10 +1442,248 @@
 )');%0A  %0A
+  console.log('spawn(generator) and cancel(task) -%3E %7B');%0A  task = yield spawn(generator, 'spawn(generator) and cancel(task)');%0A  yield call(delay, 1500)%0A  yield cancel(task);%0A  console.log(yield '%7D %3C- spawn(generator) and cancel(task)');%0A
 %7D%0A

add a code of cancel